Skip to content
Browse files

NCBC-228: Frequent pooled socket errors during rebalance

It appears that there are concurrency issues when the server
is sending frequent config updates, as is the case during
a rebalance.  Config updates trigger the client to destroy its
socket pool after first creating a new one.

This change briefly delays the destruction of the old pool
so that any in progress operations may complete.
  • Loading branch information...
1 parent 4388f4c commit e45a0fac8320fac7c8981ea9de62146043f57031 @johnzablocki johnzablocki committed Feb 19, 2013
Showing with 22 additions and 18 deletions.
  1. +22 −18 Enyim.Caching/Memcached/MemcachedNode.cs
View
40 Enyim.Caching/Memcached/MemcachedNode.cs
@@ -161,11 +161,12 @@ private bool TryToFail()
{
return false;
}
- if (Failed != null) {
+ if (Failed != null)
+ {
Failed(this);
}
return true;
- }
+ }
~MemcachedNode()
{
@@ -309,7 +310,7 @@ public IPooledSocketResult Acquire()
{
message = "Pool is dead or disposed, returning null. " + this.endPoint;
result.Fail(message);
-
+
if (hasDebug) log.Debug(message);
return result;
@@ -369,7 +370,7 @@ public IPooledSocketResult Acquire()
// free item pool is empty
message = "Could not get a socket from the pool, Creating a new item. " + this.endPoint;
if (hasDebug) log.Debug(message);
-
+
try
{
@@ -479,24 +480,27 @@ public void Dispose()
// if someone uses a pooled item then 99% that an exception will be thrown
// somewhere. But since the dispose is mostly used when everyone else is finished
// this should not kill any kittens
- if (!this.isDisposed)
+ new Timer((s) =>
{
- this.isAlive = false;
- this.isDisposed = true;
+ if (!this.isDisposed)
+ {
+ this.isAlive = false;
+ this.isDisposed = true;
- PooledSocket ps;
+ PooledSocket ps;
- while (this.freeItems.TryPop(out ps))
- {
- try { ps.Destroy(); }
- catch { }
- }
+ while (this.freeItems.TryPop(out ps))
+ {
+ try { ps.Destroy(); }
+ catch { }
+ }
- this.ownerNode = null;
- this.semaphore.Close();
- this.semaphore = null;
- this.freeItems = null;
- }
+ this.ownerNode = null;
+ this.semaphore.Close();
+ this.semaphore = null;
+ this.freeItems = null;
+ }
+ }, null, 1000, Timeout.Infinite);
}
void IDisposable.Dispose()

0 comments on commit e45a0fa

Please sign in to comment.
Something went wrong with that request. Please try again.