[JAVA-4093] "com.mongodb.MongoException: state should be: open" when concurrently accessing the client for HELP repro Created: 31/Mar/21 Updated: 27/Oct/23 Resolved: 31/Mar/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrew Shuvalov (Inactive) | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||
| Issue Links: |
|
||||
| Description |
|
The attached short repro is a simplified version of a stress test. In short, it just creates an array of MongoClient instances and is using them concurrently from other threads. This fails with "state should be: open" right at the first read. The sharded cluster backend should be any version of v4.0 branch, like 4.0.23. The Java driver could be 3.10.2, which is used by customer, but could be anything that works, initially. The versions I tried are in pom.xml - 3.10.2, 3.12.8, 4.0.6, 4.2.2. |
| Comments |
| Comment by Andrew Shuvalov (Inactive) [ 31/Mar/21 ] |
|
Thank you jeff.yemin! |
| Comment by Jeffrey Yemin [ 31/Mar/21 ] |
|
The test program has a bug. It uses try-with-resources, which implicitly calls the close method on the MongoClient when the try block is exited. So right after you add the client to the Vector, the client is closed. |
| Comment by Andrew Shuvalov (Inactive) [ 31/Mar/21 ] |
|
Is there a workaround to make this code working with existing drivers? |