Skip to content

Commit 44d8be3

Browse files
authored
fix: prevent possible connection leak in AutorecoveringConnection during creation (#1857)
* fix: prevent possible connection leak in AutorecoveringConnection during creation * fix: use "FailedOpen" reason text when closing AutorecoveringConnection after inner connection open error This matches the behavior used when normal connection opening fails.
1 parent a267025 commit 44d8be3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,28 @@ internal static async ValueTask<AutorecoveringConnection> CreateAsync(Connection
9696
.ConfigureAwait(false);
9797
Connection innerConnection = new(config, fh);
9898
AutorecoveringConnection connection = new(config, endpoints, innerConnection);
99-
await innerConnection.OpenAsync(cancellationToken)
100-
.ConfigureAwait(false);
99+
try
100+
{
101+
await innerConnection.OpenAsync(cancellationToken)
102+
.ConfigureAwait(false);
103+
}
104+
catch
105+
{
106+
try
107+
{
108+
await connection.CloseAsync(Constants.InternalError, "FailedOpen",
109+
InternalConstants.DefaultConnectionCloseTimeout, true,
110+
cancellationToken).ConfigureAwait(false);
111+
await connection.DisposeAsync()
112+
.ConfigureAwait(false);
113+
}
114+
catch
115+
{
116+
}
117+
118+
throw;
119+
}
120+
101121
return connection;
102122
}
103123

0 commit comments

Comments
 (0)