Skip to content

Commit 1811361

Browse files
committed
Tweak PooledSocket.ConnectAsync
1 parent 389716f commit 1811361

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Enyim.Caching/Memcached/PooledSocket.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,19 @@ public async Task ConnectAsync()
9595
bool success = false;
9696

9797
var connTask = _socket.ConnectAsync(_endpoint);
98+
9899
if (await Task.WhenAny(connTask, Task.Delay(_connectionTimeout)) == connTask)
99100
{
100101
await connTask;
101102
}
102-
else if (_socket != null)
103+
else
103104
{
104-
_socket.Dispose();
105-
_socket = null;
105+
if (_socket != null)
106+
{
107+
_socket.Dispose();
108+
_socket = null;
109+
}
110+
throw new TimeoutException($"Timeout to connect to {_endpoint}.");
106111
}
107112

108113
if (_socket != null)
@@ -424,21 +429,21 @@ public async Task WriteAsync(IList<ArraySegment<byte>> buffers)
424429
#region [ License information ]
425430

426431
/* ************************************************************
427-
*
432+
*
428433
* Copyright (c) 2010 Attila Kisk? enyim.com
429-
*
434+
*
430435
* Licensed under the Apache License, Version 2.0 (the "License");
431436
* you may not use this file except in compliance with the License.
432437
* You may obtain a copy of the License at
433-
*
438+
*
434439
* http://www.apache.org/licenses/LICENSE-2.0
435-
*
440+
*
436441
* Unless required by applicable law or agreed to in writing, software
437442
* distributed under the License is distributed on an "AS IS" BASIS,
438443
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
439444
* See the License for the specific language governing permissions and
440445
* limitations under the License.
441-
*
446+
*
442447
* ************************************************************/
443448

444449
#endregion

0 commit comments

Comments
 (0)