Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit e45a0fac8320fac7c8981ea9de62146043f57031 1 parent 4388f4c
John Zablocki johnzablocki authored

Showing 1 changed file with 22 additions and 18 deletions. Show diff stats Hide diff stats

  1. +22 18 Enyim.Caching/Memcached/MemcachedNode.cs
40 Enyim.Caching/Memcached/MemcachedNode.cs
@@ -161,11 +161,12 @@ private bool TryToFail()
161 161 {
162 162 return false;
163 163 }
164   - if (Failed != null) {
  164 + if (Failed != null)
  165 + {
165 166 Failed(this);
166 167 }
167 168 return true;
168   - }
  169 + }
169 170
170 171 ~MemcachedNode()
171 172 {
@@ -309,7 +310,7 @@ public IPooledSocketResult Acquire()
309 310 {
310 311 message = "Pool is dead or disposed, returning null. " + this.endPoint;
311 312 result.Fail(message);
312   -
  313 +
313 314 if (hasDebug) log.Debug(message);
314 315
315 316 return result;
@@ -369,7 +370,7 @@ public IPooledSocketResult Acquire()
369 370 // free item pool is empty
370 371 message = "Could not get a socket from the pool, Creating a new item. " + this.endPoint;
371 372 if (hasDebug) log.Debug(message);
372   -
  373 +
373 374
374 375 try
375 376 {
@@ -479,24 +480,27 @@ public void Dispose()
479 480 // if someone uses a pooled item then 99% that an exception will be thrown
480 481 // somewhere. But since the dispose is mostly used when everyone else is finished
481 482 // this should not kill any kittens
482   - if (!this.isDisposed)
  483 + new Timer((s) =>
483 484 {
484   - this.isAlive = false;
485   - this.isDisposed = true;
  485 + if (!this.isDisposed)
  486 + {
  487 + this.isAlive = false;
  488 + this.isDisposed = true;
486 489
487   - PooledSocket ps;
  490 + PooledSocket ps;
488 491
489   - while (this.freeItems.TryPop(out ps))
490   - {
491   - try { ps.Destroy(); }
492   - catch { }
493   - }
  492 + while (this.freeItems.TryPop(out ps))
  493 + {
  494 + try { ps.Destroy(); }
  495 + catch { }
  496 + }
494 497
495   - this.ownerNode = null;
496   - this.semaphore.Close();
497   - this.semaphore = null;
498   - this.freeItems = null;
499   - }
  498 + this.ownerNode = null;
  499 + this.semaphore.Close();
  500 + this.semaphore = null;
  501 + this.freeItems = null;
  502 + }
  503 + }, null, 1000, Timeout.Infinite);
500 504 }
501 505
502 506 void IDisposable.Dispose()

0 comments on commit e45a0fa

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