Skip to content

Commit 03fd9b5

Browse files
author
rstam
committed
CSHARP-791: Don't let an exception on one connection cause us to think that we are no longer connected to the server.
1 parent 82e6c70 commit 03fd9b5

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

MongoDB.Driver/Communication/MongoConnection.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,7 @@ private void HandleException(Exception ex)
356356
throw new MongoInternalException("Invalid HandleExceptionAction");
357357
}
358358

359-
// forces a call to VerifyState before the next message is sent to this server instance
360-
// this is a bit drastic but at least it's safe (and perhaps we can optimize a bit in the future)
361-
_serverInstance.SetState(MongoServerState.Unknown);
359+
_serverInstance.RefreshStateAsSoonAsPossible();
362360
}
363361

364362
private enum HandleExceptionAction

MongoDB.Driver/Communication/MongoServerInstance.cs

+8
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ public void Ping()
349349
}
350350
}
351351

352+
/// <summary>
353+
/// Refreshes the state as soon as possible.
354+
/// </summary>
355+
public void RefreshStateAsSoonAsPossible()
356+
{
357+
_stateVerificationTimer.Change(TimeSpan.Zero, TimeSpan.FromSeconds(10)); // verify state as soon as possible
358+
}
359+
352360
/// <summary>
353361
/// Verifies the state of the server instance.
354362
/// </summary>

MongoDB.Driver/MongoServerState.cs

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public enum MongoServerState
3737
/// </summary>
3838
ConnectedToSubset,
3939
/// <summary>
40-
/// The state is temporarily unknown.
41-
/// </summary>
42-
Unknown,
43-
/// <summary>
4440
/// Disconnecting from the server (in progress).
4541
/// </summary>
4642
Disconnecting

MongoDB.Driver/Operations/QueryOperation.cs

+9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ public IEnumerator<TDocument> Execute(IConnectionProvider connectionProvider)
115115
}
116116
}
117117
}
118+
catch
119+
{
120+
if (reply != null && reply.CursorId != 0)
121+
{
122+
try { KillCursor(connectionProvider, reply.CursorId); }
123+
catch { } // ignore exceptions and rethrow the original exception
124+
}
125+
throw;
126+
}
118127
finally
119128
{
120129
if (reply != null && reply.CursorId != 0)

0 commit comments

Comments
 (0)