Release imap client only when the pool fails to provide one.

This commit is contained in:
Burak Kaan Köse
2024-06-21 00:32:45 +02:00
parent f7161dc39b
commit 1659d74938

View File

@@ -456,6 +456,8 @@ namespace Wino.Core.Synchronizers
ImapClient executorClient = null; ImapClient executorClient = null;
bool isCrashed = false;
try try
{ {
executorClient = await _clientPool.GetClientAsync(); executorClient = await _clientPool.GetClientAsync();
@@ -467,11 +469,13 @@ namespace Wino.Core.Synchronizers
item.Request.RevertUIChanges(); item.Request.RevertUIChanges();
isCrashed = true;
throw; throw;
} }
finally finally
{ {
if (executorClient != null) // Make sure that the client is released from the pool for next usages if error occurs.
if (isCrashed && executorClient != null)
{ {
_clientPool.Release(executorClient); _clientPool.Release(executorClient);
} }