@@ -87,7 +87,7 @@ public bool IsAlive
87
87
88
88
/// <summary>
89
89
/// Gets a value indicating whether the server is working or not.
90
- ///
90
+ ///
91
91
/// If the server is back online, we'll ercreate the internal socket pool and mark the server as alive so operations can target it.
92
92
/// </summary>
93
93
/// <returns>true if the server is alive; false otherwise.</returns>
@@ -263,7 +263,7 @@ private class InternalPoolImpl : IDisposable
263
263
/// <summary>
264
264
/// A list of already connected but free to use sockets
265
265
/// </summary>
266
- private InterlockedStack < PooledSocket > freeItems ;
266
+ private InterlockedStack < PooledSocket > _freeItems ;
267
267
268
268
private bool isDisposed ;
269
269
private bool isAlive ;
@@ -300,7 +300,7 @@ internal InternalPoolImpl(
300
300
this . maxItems = config . MaxPoolSize ;
301
301
302
302
_semaphore = new SemaphoreSlim ( maxItems , maxItems ) ;
303
- this . freeItems = new InterlockedStack < PooledSocket > ( ) ;
303
+ _freeItems = new InterlockedStack < PooledSocket > ( ) ;
304
304
305
305
_logger = logger ;
306
306
_isDebugEnabled = _logger . IsEnabled ( LogLevel . Debug ) ;
@@ -314,7 +314,14 @@ internal void InitPool()
314
314
{
315
315
for ( int i = 0 ; i < this . minItems ; i ++ )
316
316
{
317
- this . freeItems . Push ( this . CreateSocket ( ) ) ;
317
+ try
318
+ {
319
+ _freeItems . Push ( CreateSocket ( ) ) ;
320
+ }
321
+ catch ( Exception ex )
322
+ {
323
+ _logger . LogError ( ex , $ "Failed to put { nameof ( PooledSocket ) } { i } in Pool") ;
324
+ }
318
325
319
326
// cannot connect to the server
320
327
if ( ! this . isAlive )
@@ -342,7 +349,14 @@ internal async Task InitPoolAsync()
342
349
{
343
350
for ( int i = 0 ; i < this . minItems ; i ++ )
344
351
{
345
- this . freeItems . Push ( await this . CreateSocketAsync ( ) ) ;
352
+ try
353
+ {
354
+ _freeItems . Push ( await CreateSocketAsync ( ) ) ;
355
+ }
356
+ catch ( Exception ex )
357
+ {
358
+ _logger . LogError ( ex , $ "Failed to put { nameof ( PooledSocket ) } { i } in Pool") ;
359
+ }
346
360
347
361
// cannot connect to the server
348
362
if ( ! this . isAlive )
@@ -432,7 +446,7 @@ public IPooledSocketResult Acquire()
432
446
}
433
447
434
448
// do we have free items?
435
- if ( this . freeItems . TryPop ( out retval ) )
449
+ if ( _freeItems . TryPop ( out retval ) )
436
450
{
437
451
#region [ get it from the pool ]
438
452
@@ -538,7 +552,7 @@ public async Task<IPooledSocketResult> AcquireAsync()
538
552
}
539
553
540
554
// do we have free items?
541
- if ( this . freeItems . TryPop ( out retval ) )
555
+ if ( _freeItems . TryPop ( out retval ) )
542
556
{
543
557
#region [ get it from the pool ]
544
558
@@ -643,7 +657,7 @@ private void ReleaseSocket(PooledSocket socket)
643
657
try
644
658
{
645
659
// mark the item as free
646
- this . freeItems . Push ( socket ) ;
660
+ _freeItems . Push ( socket ) ;
647
661
}
648
662
finally
649
663
{
@@ -679,7 +693,7 @@ private void ReleaseSocket(PooledSocket socket)
679
693
{
680
694
try
681
695
{
682
- // one of our previous sockets has died, so probably all of them
696
+ // one of our previous sockets has died, so probably all of them
683
697
// are dead. so, kill the socket (this will eventually clear the pool as well)
684
698
socket . Destroy ( ) ;
685
699
}
@@ -716,7 +730,7 @@ public void Dispose()
716
730
717
731
PooledSocket ps ;
718
732
719
- while ( this . freeItems . TryPop ( out ps ) )
733
+ while ( _freeItems . TryPop ( out ps ) )
720
734
{
721
735
try { ps . Destroy ( ) ; }
722
736
catch { }
@@ -725,7 +739,7 @@ public void Dispose()
725
739
this . ownerNode = null ;
726
740
_semaphore . Dispose ( ) ;
727
741
_semaphore = null ;
728
- this . freeItems = null ;
742
+ _freeItems = null ;
729
743
}
730
744
}
731
745
@@ -904,7 +918,7 @@ protected virtual async Task<bool> ExecuteOperationAsync(IOperation op, Action<b
904
918
var socket = ( await this . AcquireAsync ( ) ) . Value ;
905
919
if ( socket == null ) return false ;
906
920
907
- //key(string) to buffer(btye[])
921
+ //key(string) to buffer(btye[])
908
922
var b = op . GetBuffer ( ) ;
909
923
910
924
try
@@ -982,20 +996,20 @@ event Action<IMemcachedNode> IMemcachedNode.Failed
982
996
983
997
#region [ License information ]
984
998
/* ************************************************************
985
- *
999
+ *
986
1000
* Copyright (c) 2010 Attila Kisk? enyim.com
987
- *
1001
+ *
988
1002
* Licensed under the Apache License, Version 2.0 (the "License");
989
1003
* you may not use this file except in compliance with the License.
990
1004
* You may obtain a copy of the License at
991
- *
1005
+ *
992
1006
* http://www.apache.org/licenses/LICENSE-2.0
993
- *
1007
+ *
994
1008
* Unless required by applicable law or agreed to in writing, software
995
1009
* distributed under the License is distributed on an "AS IS" BASIS,
996
1010
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
997
1011
* See the License for the specific language governing permissions and
998
1012
* limitations under the License.
999
- *
1013
+ *
1000
1014
* ************************************************************/
1001
1015
#endregion
0 commit comments