[JAVA-263] NullPointerException due to race condition during concurrent access to DBTCPTransport Created: 01/Feb/11 Updated: 17/Mar/11 Resolved: 22/Feb/11 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.4, 2.5 |
| Fix Version/s: | 2.5 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Mike Copley | Assignee: | Antoine Girbal |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Single MongoDB instance, Java 6 (OS X 10.6.6). |
||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
DBTCPConnector._set() is susceptible to a race condition where two threads call it at the same time, allowing a thread to mistaking think _masterPortPool is set when it is still null, and go on to cause a NullPointerException in DBTCPConnector$MyPort.get(). Further detail: I have two threads invoking DB.getCollection("differentCollectionForEachThread").drop() at approximately the same time. These are the first connections to Mongo. Approximately every 2nd run of this causes a NullPointerException in DBTCPConnector$MyPort.get(). I've tried to make a simple test app to reproduce, but can't - timing issues are tricky to replicate. The problem occurs here: private boolean _set( ServerAddress addr ) { if ( _curMaster == addr) // should check that _masterPortPool != null return false; _curMaster = addr; // _curMaster set before _masterPortPool. At this point _masterPortPool is still null. _masterPortPool = _portHolder.get( addr ); return true; }Then in MyPort.get() the NPE happens: _pool = _masterPortPool; In the above code,
Stack Trace (based on git head, commit a052b4f35af4069121cbf47adc88d6199563c4d4): java.lang.NullPointerException Suggested fix: private boolean _set( ServerAddress addr ) { if ( _curMaster == addr && _masterPortPool != null) return false; _curMaster = addr; _masterPortPool = _portHolder.get( addr ); return true; } |
| Comments |
| Comment by Antoine Girbal [ 22/Feb/11 ] |
|
considering resolved until further report |
| Comment by Antoine Girbal [ 17/Feb/11 ] |
|
did some refactoring for dbtcpconnector.
|
| Comment by auto [ 17/Feb/11 ] |
|
Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}Message: |
| Comment by auto [ 17/Feb/11 ] |
|
Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}Message: |
| Comment by Antoine Girbal [ 16/Feb/11 ] |
|
looking at it |
| Comment by Mike Copley [ 16/Feb/11 ] |
|
Sounds like this case needs to be reopened then. Perhaps a more comprehensive synchronized block is required for this task. |
| Comment by David Dawson [ 14/Feb/11 ] |
|
We've seen this error quite a bit. We took 2.5 trunk (with this fix applied) and ran with that for a while to see what result we could get, however we are still seeing occasional NPE on this code (although much reduced) java.lang.NullPointerException |
| Comment by auto [ 08/Feb/11 ] |
|
Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}Message: |
| Comment by Antoine Girbal [ 08/Feb/11 ] |
|
thanks for report, fixed. |
| Comment by auto [ 08/Feb/11 ] |
|
Author: {u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}Message: |