[JAVA-3206] Fix connection pool race condition Created: 14/Feb/19  Updated: 28/Oct/23  Resolved: 27/Feb/19

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: None
Fix Version/s: 3.11.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


 Description   

There is a race condition in the DefaultConnectionPool class between the maintenance task thread and the constructor for the class. The race can be fixed by deferring starting the maintenance task thread to a start method that's called immediately after the constructor completes, which will ensure that all final fields of the class are published (in the JVM memory model sense of the word)



 Comments   
Comment by Githook User [ 27/Feb/19 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Fix race condition in DefaultConnectionPool constructor

The race condition is due to the constructor starting a thread which
access final fields of the containing class. Since the thread may
execute before the constructor completes, there is no guarantee that
the final fields have been "published" to main memory, and therefore
the fields set in the constructor may not be visible to the thread
immediately.

The fix is to defer starting the thread to a start method that the
driver should call immediately after construction.

JAVA-3206
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/8c9b9b8160f2f50075181f9532e6ae3991383b02

Generated at Thu Feb 08 08:59:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.