[JAVA-3433] Concurrency issue when closing server session pool Created: 12/Sep/19  Updated: 28/Oct/23  Resolved: 31/Oct/19

Status: Closed
Project: Java Driver
Component/s: Session Management
Affects Version/s: None
Fix Version/s: 3.11.2

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: John Stewart (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

https://evergreen.mongodb.com/task/mongo_java_driver_tests_jdk_newer_secure__version~latest_os~linux_topology~sharded_cluster_auth~auth_ssl~ssl_jdk~jdk8_test_06b544159bdbb453261bb3aeed0dd688c79024ad_19_09_12_15_45_23

FAILURE: java.lang.NullPointerException (java.lang.NullPointerException)
java.lang.NullPointerException
	at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:81)
	at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:37)
	at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
	at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:136)
	at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:115)
	at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
	at com.mongodb.internal.connection.RequestMessage.addDocument(RequestMessage.java:238)
	at com.mongodb.internal.connection.RequestMessage.addDocument(RequestMessage.java:188)
	at com.mongodb.internal.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:140)
	at com.mongodb.internal.connection.RequestMessage.encode(RequestMessage.java:138)
	at com.mongodb.internal.connection.CommandMessage.encode(CommandMessage.java:61)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:248)
	at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:450)
	at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72)
	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:218)
	at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269)
	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131)
	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123)
	at com.mongodb.internal.session.ServerSessionPool.endClosedSessions(ServerSessionPool.java:143)
	at com.mongodb.internal.session.ServerSessionPool.close(ServerSessionPool.java:97)
	at com.mongodb.async.client.MongoClientImpl.close(MongoClientImpl.java:115)
	at com.mongodb.async.client.TransactionsTest.cleanUp(TransactionsTest.java:306)



 Comments   
Comment by Githook User [ 05/Nov/19 ]

Author:

{'name': 'John Stewart', 'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com'}

Message: Fix concurrency issue when closing sessions in ServerSessionPool

JAVA-3433
Branch: 3.11.x
https://github.com/mongodb/mongo-java-driver/commit/33b86f784279b3c69ac8e456698426a969794e05

Comment by Githook User [ 31/Oct/19 ]

Author:

{'username': 'jstewart-mongo', 'email': 'john.stewart@mongodb.com', 'name': 'John Stewart'}

Message: Fix concurrency issue when closing sessions in ServerSessionPool

JAVA-3433
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4d8e06c76a3bcb7e9129f37b3aa1d51f7842fe3f

Comment by John Stewart (Inactive) [ 27/Oct/19 ]

jeff.yemin I did see that there was some defensive code in the close and closeSession methods in ServerSessionPool, but after considering your suggestion, I can see where the concurrency issue can occur. Reopening to investigate further.

Comment by Jeffrey Yemin [ 27/Oct/19 ]

In that case I would suspect a concurrency issue in the ServerSessionPool. It does look like closedSessionIdentifiers could be involved in a race condition if ServerSessionPool#close executes concurrently with ServerSessionPool#closeSession.

Comment by John Stewart (Inactive) [ 25/Oct/19 ]

The failure did not reproduce either locally or on Evergreen using the commit where the failure appeared. It can be surmised that the value from the BsonArray in `BsonArrayCodec#encode` became null, but analyzing the call stack did not produce a scenario in which this could happen. The method `Object#getClass` cannot return null, and `codecRegistry` has a `notNull` annotation.

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