Skip to content

Commit f95fcd0

Browse files
committed
fix: prevent possible connection leak in AutorecoveringConnection during creation
1 parent a267025 commit f95fcd0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,27 @@ 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(cancellationToken)
109+
.ConfigureAwait(false);
110+
await connection.DisposeAsync()
111+
.ConfigureAwait(false);
112+
}
113+
catch
114+
{
115+
}
116+
117+
throw;
118+
}
119+
101120
return connection;
102121
}
103122

0 commit comments

Comments
 (0)