@@ -40,41 +40,47 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
40
40
}
41
41
if ( session != null )
42
42
{
43
- if ( session . PoolGeneration != m_generation || ! await session . TryPingAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) )
43
+ bool reuseSession ;
44
+
45
+ if ( session . PoolGeneration != m_generation )
44
46
{
45
- // session is either old or cannot communicate with the server
46
- await session . DisposeAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
47
+ reuseSession = false ;
47
48
}
48
49
else
49
50
{
50
- bool resetFailed = false ;
51
-
52
- // session is valid, reset if supported
53
51
if ( m_connectionSettings . ConnectionReset )
54
52
{
55
53
try
56
54
{
57
55
// Depending on the server (Aurora?), this can randomly fail when re-authenticating to the server.
58
56
// If it does, we can just pretend it didn't happen and continue with creating a new session below.
59
57
await session . ResetConnectionAsync ( m_connectionSettings , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
58
+ reuseSession = true ;
60
59
}
61
- catch
60
+ catch ( Exception )
62
61
{
63
- resetFailed = true ;
64
-
65
- await session . DisposeAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
62
+ reuseSession = false ;
66
63
}
67
64
}
68
-
69
- if ( ! resetFailed )
65
+ else
70
66
{
71
- // pooled session is ready to be used; return it
72
- session . OwningConnection = new WeakReference < MySqlConnection > ( connection ) ;
73
- lock ( m_leasedSessions )
74
- m_leasedSessions . Add ( session . Id , session ) ;
75
- return session ;
67
+ reuseSession = await session . TryPingAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
76
68
}
77
69
}
70
+
71
+ if ( ! reuseSession )
72
+ {
73
+ // session is either old or cannot communicate with the server
74
+ await session . DisposeAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
75
+ }
76
+ else
77
+ {
78
+ // pooled session is ready to be used; return it
79
+ session . OwningConnection = new WeakReference < MySqlConnection > ( connection ) ;
80
+ lock ( m_leasedSessions )
81
+ m_leasedSessions . Add ( session . Id , session ) ;
82
+ return session ;
83
+ }
78
84
}
79
85
80
86
// create a new session
0 commit comments