Skip to content

Commit 8b90269

Browse files
committed
Set OwningConnection for non-pooled connections. Fixes #674
1 parent 13d7fa6 commit 8b90269

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ private async ValueTask<ServerSession> CreateSessionAsync(ConnectionPool pool, I
632632
RandomLoadBalancer.Instance : FailOverLoadBalancer.Instance;
633633

634634
var session = new ServerSession();
635+
session.OwningConnection = new WeakReference<MySqlConnection>(this);
635636
Log.Info("Created new non-pooled Session{0}", session.Id);
636637
await session.ConnectAsync(m_connectionSettings, loadBalancer, actualIOBehavior, connectToken).ConfigureAwait(false);
637638
return session;
@@ -762,9 +763,14 @@ private async Task DoCloseAsync(bool changeState, IOBehavior ioBehavior)
762763
if (m_session is object)
763764
{
764765
if (m_connectionSettings.Pooling)
766+
{
765767
m_session.ReturnToPool();
768+
}
766769
else
770+
{
767771
await m_session.DisposeAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
772+
m_session.OwningConnection = null;
773+
}
768774
m_session = null;
769775
}
770776

0 commit comments

Comments
 (0)