Skip to content

Commit 4435763

Browse files
committed
Dispose old session on reconnect
1 parent cb53850 commit 4435763

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Renci.SshNet/BaseClient.cs

+10
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public void Connect()
240240
var session = Session;
241241
if (session is null || !session.IsConnected)
242242
{
243+
if (session is not null)
244+
{
245+
DisposeSession(session);
246+
}
247+
243248
Session = CreateAndConnectSession();
244249
}
245250

@@ -304,6 +309,11 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
304309
var session = Session;
305310
if (session is null || !session.IsConnected)
306311
{
312+
if (session is not null)
313+
{
314+
DisposeSession(session);
315+
}
316+
307317
Session = await CreateAndConnectSessionAsync(cancellationToken).ConfigureAwait(false);
308318
}
309319

0 commit comments

Comments
 (0)