diff --git a/source/MongoDB/Connections/Connection.cs b/source/MongoDB/Connections/Connection.cs index c0d80a07..da085cca 100644 --- a/source/MongoDB/Connections/Connection.cs +++ b/source/MongoDB/Connections/Connection.cs @@ -97,20 +97,20 @@ internal ReplyMessage SendTwoWayMessageCore(IRequestMessage message, BsonR { EnsureOpenConnection(); - try - { - var reply = new ReplyMessage(readerSettings); - lock(_connection) - { - message.Write(_connection.GetStream()); - reply.Read(_connection.GetStream()); - } - return reply; - } - catch(IOException) + lock(_connection) { - ReplaceInvalidConnection(); - throw; + try + { + var reply = new ReplyMessage(readerSettings); + message.Write(_connection.GetStream()); + reply.Read(_connection.GetStream()); + return reply; + } + catch(IOException) + { + ReplaceInvalidConnection(); + throw; + } } } @@ -133,20 +133,20 @@ public void SendMessage(IRequestMessage message, string database){ internal void SendMessageCore(IRequestMessage message) { EnsureOpenConnection(); - - try - { - lock(_connection) - { - message.Write(_connection.GetStream()); - } - } - catch(IOException) + lock(_connection) { - //Sending doesn't seem to always trigger the detection of a closed socket. - ReplaceInvalidConnection(); - throw; + try + { + message.Write(_connection.GetStream()); + } + catch(IOException) + { + //Sending doesn't seem to always trigger the detection of a closed socket. + ReplaceInvalidConnection(); + throw; + } } + } ///