Skip to content

Commit

Permalink
Merge pull request #154 from cnblogs/fix-socketpool-starvation
Browse files Browse the repository at this point in the history
Fix socketpool starvation
  • Loading branch information
cnblogs-dudu authored Dec 2, 2020
2 parents b3dac1c + f0dcbb5 commit 3b8eaea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Enyim.Caching/Enyim.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>EnyimMemcachedCore is a Memcached client library for .NET Core. Usage: Add services.AddEnyimMemcached(...) and app.UseEnyimMemcached() in Startup. Add IMemcachedClient into constructor.</Description>
<Authors>cnblogs.com</Authors>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>EnyimMemcachedCore</AssemblyName>
<PackageId>EnyimMemcachedCore</PackageId>
Expand Down
13 changes: 8 additions & 5 deletions Enyim.Caching/Memcached/MemcachedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,11 @@ public async Task<IPooledSocketResult> AcquireAsync()
// maybe we died while waiting
if (!this.isAlive)
{
_semaphore.Release();

message = "Pool is dead, returning null. " + _endPoint;
if (_isDebugEnabled) _logger.LogDebug(message);
result.Fail(message);

return result;
}

Expand All @@ -573,9 +574,11 @@ public async Task<IPooledSocketResult> AcquireAsync()
}
else
{
_semaphore.Release();
retval.IsAlive = false;

message = "Timeout to reset an acquired socket. InstanceId " + retval.InstanceId;
_logger.LogError(message);
MarkAsDead();
result.Fail(message);
return result;
}
Expand All @@ -589,10 +592,11 @@ public async Task<IPooledSocketResult> AcquireAsync()
}
catch (Exception e)
{
MarkAsDead();
_semaphore.Release();

message = "Failed to reset an acquired socket.";
_logger.LogError(message, e);

this.MarkAsDead();
result.Fail(message, e);
return result;
}
Expand Down Expand Up @@ -945,7 +949,6 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati
_logger.LogError(errorMsg);
return result;
}

}

protected virtual async Task<bool> ExecuteOperationAsync(IOperation op, Action<bool> next)
Expand Down

0 comments on commit 3b8eaea

Please sign in to comment.