@@ -176,15 +176,10 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
176176 operationSucceeded = true ;
177177 return resp ;
178178 }
179- catch ( TException retryEx )
180- {
181- // Reconnection failed, client is closed and should not be returned to pool
182- shouldReturnClient = false ;
183- throw new TException ( errMsg , retryEx ) ;
184- }
185179 catch ( Exception retryEx )
186180 {
187- // Reconnection failed with non-TException, client is closed and should not be returned to pool
181+ // Reconnection failed or retry operation failed
182+ // Client is closed by Reconnect, should not be returned to pool
188183 shouldReturnClient = false ;
189184 throw new TException ( errMsg , retryEx ) ;
190185 }
@@ -205,15 +200,10 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
205200 operationSucceeded = true ;
206201 return resp ;
207202 }
208- catch ( TException retryEx )
209- {
210- // Reconnection failed, client is closed and should not be returned to pool
211- shouldReturnClient = false ;
212- throw new TException ( errMsg , retryEx ) ;
213- }
214203 catch ( Exception retryEx )
215204 {
216- // Reconnection failed with non-TException, client is closed and should not be returned to pool
205+ // Reconnection failed or retry operation failed
206+ // Client is closed by Reconnect, should not be returned to pool
217207 shouldReturnClient = false ;
218208 throw new TException ( errMsg , retryEx ) ;
219209 }
@@ -226,10 +216,12 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
226216 finally
227217 {
228218 // Return client to pool if:
229- // 1. putClientBack is true (normal operations), OR
230- // 2. putClientBack is false BUT operation failed (query operations where SessionDataSet wasn't created)
231- // Do NOT return if reconnection failed (shouldReturnClient is false) because client was closed
232- if ( shouldReturnClient && ( putClientBack || ! operationSucceeded ) )
219+ // 1. putClientBack is true (normal operations - client should always be returned), OR
220+ // 2. putClientBack is false (query operations) BUT operation failed, meaning SessionDataSet
221+ // wasn't created and won't manage the client
222+ // Do NOT return if reconnection failed (shouldReturnClient is false) because client was closed by Reconnect
223+ bool shouldReturnForQueryFailure = ! putClientBack && ! operationSucceeded ;
224+ if ( shouldReturnClient && ( putClientBack || shouldReturnForQueryFailure ) )
233225 {
234226 _clients . Add ( client ) ;
235227 }
0 commit comments