[JAVA-4490] Reference count check is not atomic with release Created: 10/Feb/22 Updated: 28/Oct/23 Resolved: 10/Feb/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Reactive Streams |
| Affects Version/s: | None |
| Fix Version/s: | 4.5.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Jeffrey Yemin | Assignee: | Jeffrey Yemin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Documentation Changes: | Not Needed | ||||||||
| Description |
|
This race condition showed up in a unit test but it seems possible, though rare, that it could affect an application using the driver. The issue is that DefaultServer.AsyncOperationCountTrackingConnection#release is not synchronized, and it some circumstances be called concurrently. So if the timing is just wrong, multiple concurrent calls can observe a 0 reference count, resulting in the operation count decrementing below 0, which in turn causes an assertion to fire. There are several approaches to fixing this, but the cleanest is to change the RefererenceCounted#release method to atomically return the decremented count and compare the returned value to 0. |
| Comments |
| Comment by Githook User [ 10/Feb/22 ] |
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Make reference count check atomic with release (#876) Co-authored-by: Valentin Kovalenko <valentin.kovalenko@mongodb.com> |