[JAVA-1873] ConnectionPoolStatisticsMBean reports incorrect wait queue size if some thread was not able to enter the queue Created: 24/Jun/15  Updated: 16/Jul/15  Resolved: 15/Jul/15

Status: Closed
Project: Java Driver
Component/s: Connection Management, Monitoring
Affects Version/s: 2.12.4, 3.0.2
Fix Version/s: 3.0.3, 3.1.0

Type: Bug Priority: Minor - P4
Reporter: Filipp Zhinkin Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File wait_queue_events_fix.patch    

 Description   

com.mongodb.connection.DefaultConnectionPool::get invoke ConnectionPoolListener::waitQueueEntered only when it is actually possible to enter the queue (waitQueueSize <= MaxWaitQueueSize), but ConnectionPoolListener::waitQueueExited is invoked in finally clause every time DefaultConnectionPool::get is invoked (https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/connection/DefaultConnectionPool.java#L84).

As a result, every time MongoWaitQueueFullException is thrown due to full wait queue, waitQueueSize in com.mongodb.management.ConnectionPoolStatistics is decremented. And eventually it may become negative.

I've hit this issue with pretty old 2.12.4 driver, but according to sources it should be reproducible with latest driver.

Suggested fix in attachment.



 Comments   
Comment by Jeffrey Yemin [ 16/Jul/15 ]

Fix is now available in the 3.0.3 release.

Comment by Githook User [ 15/Jul/15 ]

Author:

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

Message: In the connection pool, moved wait queue size increment into its own try block so that wait queue start and end events are only delivered if the wait queue is actually entered.

JAVA-1873
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/f7bb1d7e51c7251d558b1a9ffe802389cc22e798

Comment by Githook User [ 15/Jul/15 ]

Author:

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

Message: In the connection pool, moved wait queue size increment into its own try block so that wait queue start and end events are only delivered if the wait queue is actually entered.

JAVA-1873
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/378cbe769ac884e9eb1b0787e8663f6be6adb941

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'fzhinkin', u'name': u'Filipp Zhinkin', u'email': u'filipp.zhinkin@gmail.com'}

Message: Notify listener about wait queue enter before throwing an exception if the queue is full.

JAVA-1873
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/93fb8501c9afd0d9e5dae637ec29a85e318dc7ef

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'fzhinkin', u'name': u'Filipp Zhinkin', u'email': u'filipp.zhinkin@gmail.com'}

Message: Notify listener about wait queue enter before throwing an exception if the queue is full.

JAVA-1873
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/34ad2bbf421bcb2436c1b2b6b880f548de0e0a4d

Comment by Jeffrey Yemin [ 24/Jun/15 ]

Thanks Filipp,

Would you like to open a pull request so that your name is associated with the fix in the Github commit?

Regards,
Jeff

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