[CSHARP-534] MongoServerInstance.AcquireConnection throws InvalidOperationException Created: 23/Jul/12  Updated: 20/Mar/14  Resolved: 12/Nov/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.5
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Aristarkh Zagorodnikov Assignee: Unassigned
Resolution: Done Votes: 0
Labels: exception
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-474 Review all exceptions thrown by the C... Closed
Backwards Compatibility: Minor Change

 Description   

When server instance gets disconnected and state verification have not yet kicked in, MongoServerInstance.AcquireConnection throws InvalidOperationException("Server instance XXX is no longer connected."). While this is an internal state problem (so IOE fits the scheme), I think it should be treated as a transient connection error and instead throw a MongoConnectionException (with the same message). For us, the exception types are really important, because we've built an auto-retry mechanism around driver calls, and catching something as ambiguous as InvalidOperationException makes robust error handling hard enough.



 Comments   
Comment by Craig Wilson [ 12/Nov/12 ]

Sounds good. Thanks...

Comment by Aristarkh Zagorodnikov [ 12/Nov/12 ]

Since the linked issue completely encompasses this case, I think this issue can be closed as CSHARP-153 was.

Comment by Craig Wilson [ 12/Nov/12 ]

We have a ticket for reviewing all the exceptions thrown by the driver and, in most cases, will be wrapping them in a MongoXXXException. I'm going to link this ticket to that one in order to make sure this one gets covered.

Comment by Aristarkh Zagorodnikov [ 24/Jul/12 ]

System.InvalidOperationException: Server instance fs.drive.bru:27017 is no longer connected.
at MongoDB.Driver.MongoServerInstance.AcquireConnection(MongoDatabase database) in C:\Users\onyXMaster\Projects\bru\dependencies-source\MongoDB\mongo-csharp-driver\git\Driver\Core\MongoServerInstance.cs:line 288
at MongoDB.Driver.MongoServer.RequestStart(MongoDatabase initialDatabase, Boolean slaveOk) in C:\Users\onyXMaster\Projects\bru\dependencies-source\MongoDB\mongo-csharp-driver\git\Driver\Core\MongoServer.cs:line 1062
at MongoDB.Driver.GridFS.MongoGridFS.Upload(Stream stream, String remoteFileName, MongoGridFSCreateOptions createOptions) in C:\Users\onyXMaster\Projects\bru\dependencies-source\MongoDB\mongo-csharp-driver\git\Driver\GridFS\MongoGridFS.cs:line 780
...

Line numbers are from our patched 1.4 version, so take them with a grain of salt =)

Comment by Aristarkh Zagorodnikov [ 24/Jul/12 ]

I work against the 1.4 version, but testing with master shows the same behavior. This occurs when we use the GridFS API that in it's turn uses the RequestStart wrapper to ensure that all same-file requests go to the same server. I guess that all code using RequestStart would be susceptible to this issue.

Comment by Craig Wilson [ 24/Jul/12 ]

1) Are you working against the published 1.5 driver or have you built from master?
2) It seems like the type of error you are describing would happen in the background... where are you catching these exceptions? Perhaps you could provide some sample code of where this exception shows up in user code.

Generated at Wed Feb 07 21:37:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.