Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix memory leak when replacing invalid connections on multi threaded environment. #40

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+25 −25
Split
@@ -97,20 +97,20 @@ public Connection(IConnectionFactory factory)
{
EnsureOpenConnection();
- try
- {
- var reply = new ReplyMessage<T>(readerSettings);
- lock(_connection)
- {
- message.Write(_connection.GetStream());
- reply.Read(_connection.GetStream());
- }
- return reply;
- }
- catch(IOException)
+ lock(_connection)
{
- ReplaceInvalidConnection();
- throw;
+ try
+ {
+ var reply = new ReplyMessage<T>(readerSettings);
+ message.Write(_connection.GetStream());
+ reply.Read(_connection.GetStream());
+ return reply;
+ }
+ catch(IOException)
+ {
+ ReplaceInvalidConnection();
+ throw;
+ }
}
}
@@ -133,20 +133,20 @@ public Connection(IConnectionFactory factory)
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;
+ }
}
+
}
/// <summary>