Skip to content

Commit 5d00840

Browse files
committed
Remove session before awaiting it.
This will prevent the code from going into a loop if awaiting the reset task throws an exception.
1 parent 583be72 commit 5d00840

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/MySqlConnector/Core/BackgroundConnectionResetHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ public static async Task ReturnSessionsAsync()
109109
var completedTask = await Task.WhenAny(localTasks).ConfigureAwait(false);
110110
var index = localTasks.IndexOf(completedTask);
111111
var session = localSessions[index].Session;
112-
await session.Pool!.ReturnAsync(IOBehavior.Asynchronous, session).ConfigureAwait(false);
112+
var connection = localSessions[index].OwningConnection;
113113
localSessions.RemoveAt(index);
114114
localTasks.RemoveAt(index);
115+
await session.Pool!.ReturnAsync(IOBehavior.Asynchronous, session).ConfigureAwait(false);
116+
GC.KeepAlive(connection);
115117
}
116118
}
117119
}

0 commit comments

Comments
 (0)