Skip to content

Commit acd1f4e

Browse files
CopilotCritasWang
andcommitted
Fix SessionPool client return bug on reconnection failure
- Add shouldReturnClient flag to track reconnection status - Set flag to false when reconnection fails to prevent returning closed clients - Prevents pool from accumulating dead clients when operations fail Co-authored-by: CritasWang <19721744+CritasWang@users.noreply.github.com>
1 parent 27cfabd commit acd1f4e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/Apache.IoTDB/SessionPool.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ protected internal SessionPool(List<string> nodeUrls, string username, string pa
157157
public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<TResult> operation, string errMsg, bool retryOnFailure = true, bool putClientBack = true)
158158
{
159159
Client client = _clients.Take();
160+
bool shouldReturnClient = true;
160161
try
161162
{
162163
var resp = await operation(client);
@@ -173,6 +174,8 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
173174
}
174175
catch (TException retryEx)
175176
{
177+
// Reconnection failed, client is closed and should not be returned to pool
178+
shouldReturnClient = false;
176179
throw new TException(errMsg, retryEx);
177180
}
178181
}
@@ -192,6 +195,8 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
192195
}
193196
catch (TException retryEx)
194197
{
198+
// Reconnection failed, client is closed and should not be returned to pool
199+
shouldReturnClient = false;
195200
throw new TException(errMsg, retryEx);
196201
}
197202
}
@@ -202,7 +207,7 @@ public async Task<TResult> ExecuteClientOperationAsync<TResult>(AsyncOperation<T
202207
}
203208
finally
204209
{
205-
if (putClientBack)
210+
if (putClientBack && shouldReturnClient)
206211
{
207212
_clients.Add(client);
208213
}

0 commit comments

Comments
 (0)