[JAVA-5107] Fix race condition in ClientSession#close Created: 15/Aug/23 Updated: 28/Oct/23 Resolved: 16/Aug/23 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Sessions |
| Affects Version/s: | None |
| Fix Version/s: | 4.11.0 |
| Type: | Bug | Priority: | Minor - P4 |
| 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 | ||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||
| Description |
|
The sessions specification says that ClientSession should not attempt to implement any thread safety guarantees, and the Java driver does not do so. But the interpretation of that with respect to ClientSession#close leads to a race condition if multiple threads call the method concurrently on the same instance. This race can lead to duplicate server sessions added to the server session pool, which is undesirable. The driver should protect against this in ClientSession#close by using proper thread synchronization (e.g. AtomicBoolean#compareAndSet. |
| Comments |
| Comment by Githook User [ 16/Aug/23 ] |
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Make the ClientSession#close method thread-safe (#1179) Replace the volatile boolean with an AtomicBoolean
|