Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,24 @@ private bool TryPerformAutomaticRecovery()
catch (Exception e)
{
ESLog.Error("Exception when recovering connection. Will try again after retry interval.", e);

try
{
/*
* To prevent connection leaks on the next recovery loop,
* we abort the delegated connection if it is still open.
* We do not want to block the abort forever (potentially deadlocking recovery),
* so we specify the same configured timeout used for connection.
*/
if (_delegate?.IsOpen == true)
{
_delegate.Abort(Constants.InternalError, "FailedAutoRecovery", ShutdownInitiator.Library, _factory.RequestedConnectionTimeout);
}
}
catch (Exception e2)
{
ESLog.Warn("Exception when aborting previous auto recovery connection.", e2);
}
}

return false;
Expand Down Expand Up @@ -672,7 +690,6 @@ private void Init(IFrameHandler fh)
lock (_eventLock)
{
ConnectionShutdown += recoveryListener;
_recordedShutdownEventHandlers += recoveryListener;
}
}

Expand Down
10 changes: 9 additions & 1 deletion projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHa
_model0 = (ModelBase)Protocol.CreateModel(_session0);

StartMainLoop(factory.UseBackgroundThreadsForIO);
Open(insist);
try
{
Open(insist);
}
catch
{
TerminateMainloop();
throw;
}
}

public Guid Id { get { return _id; } }
Expand Down
7 changes: 4 additions & 3 deletions projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,18 @@ public void Close()
try
{
_channelWriter.Complete();
_writerTask.GetAwaiter().GetResult();
_writerTask?.GetAwaiter().GetResult();
}
catch(Exception)
catch
{
// ignore, we are closing anyway
}

try
{
_socket.Close();
}
catch (Exception)
catch
{
// ignore, we are closing anyway
}
Expand Down