Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
57f1c3b9
Commit
57f1c3b9
authored
Jan 20, 2015
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #129 from PashaPash/connect-timeout-fix
Fixed connect timeout handling in ConnectionMultiplexer.Connect
parents
f66a1070
4ab1870c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
28 deletions
+67
-28
ConnectToUnexistingHost.cs
StackExchange.Redis.Tests/ConnectToUnexistingHost.cs
+52
-0
StackExchange.Redis.Tests.csproj
StackExchange.Redis.Tests/StackExchange.Redis.Tests.csproj
+1
-0
ConnectionMultiplexer.cs
...change.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
+13
-27
SocketManager.cs
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
+1
-1
No files found.
StackExchange.Redis.Tests/ConnectToUnexistingHost.cs
0 → 100644
View file @
57f1c3b9
using
NUnit.Framework
;
using
System
;
using
System.Diagnostics
;
using
System.Threading
;
namespace
StackExchange.Redis.Tests
{
[
TestFixture
]
public
class
ConnectToUnexistingHost
:
TestBase
{
#if DEBUG
[
Test
]
[
TestCase
(
CompletionType
.
Any
)]
[
TestCase
(
CompletionType
.
Sync
)]
[
TestCase
(
CompletionType
.
Async
)]
public
void
ConnectToUnexistingHostFailsWithinTimeout
(
CompletionType
completionType
)
{
var
sw
=
Stopwatch
.
StartNew
();
try
{
var
config
=
new
ConfigurationOptions
{
EndPoints
=
{
{
"invalid"
,
1234
}
},
ConnectTimeout
=
1000
};
SocketManager
.
ConnectCompletionType
=
completionType
;
using
(
var
muxer
=
ConnectionMultiplexer
.
Connect
(
config
))
{
Thread
.
Sleep
(
10000
);
}
Assert
.
Fail
(
"Connect should fail with RedisConnectionException exception"
);
}
catch
(
RedisConnectionException
)
{
var
elapsed
=
sw
.
ElapsedMilliseconds
;
if
(
elapsed
>
9000
)
{
Assert
.
Fail
(
"Connect should fail within ConnectTimeout"
);
}
}
finally
{
SocketManager
.
ConnectCompletionType
=
CompletionType
.
Any
;
}
}
#endif
}
}
\ No newline at end of file
StackExchange.Redis.Tests/StackExchange.Redis.Tests.csproj
View file @
57f1c3b9
...
...
@@ -67,6 +67,7 @@
<Compile
Include=
"AsyncTests.cs"
/>
<Compile
Include=
"BasicOps.cs"
/>
<Compile
Include=
"ConnectingFailDetection.cs"
/>
<Compile
Include=
"ConnectToUnexistingHost.cs"
/>
<Compile
Include=
"HyperLogLog.cs"
/>
<Compile
Include=
"WrapperBaseTests.cs"
/>
<Compile
Include=
"TransactionWrapperTests.cs"
/>
...
...
StackExchange.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
View file @
57f1c3b9
...
...
@@ -718,48 +718,34 @@ static ConnectionMultiplexer CreateMultiplexer(object configuration)
/// </summary>
public
static
ConnectionMultiplexer
Connect
(
string
configuration
,
TextWriter
log
=
null
)
{
IDisposable
killMe
=
null
;
try
{
var
muxer
=
CreateMultiplexer
(
configuration
);
killMe
=
muxer
;
// note that task has timeouts internally, so it might take *just over* the reegular timeout
var
task
=
muxer
.
ReconfigureAsync
(
true
,
false
,
log
,
null
,
"connect"
);
if
(!
task
.
Wait
(
muxer
.
SyncConnectTimeout
(
true
)))
{
task
.
ObserveErrors
();
if
(
muxer
.
RawConfig
.
AbortOnConnectFail
)
{
throw
new
TimeoutException
();
}
}
if
(!
task
.
Result
)
throw
ExceptionFactory
.
UnableToConnect
(
muxer
.
failureMessage
);
killMe
=
null
;
return
muxer
;
}
finally
{
if
(
killMe
!=
null
)
try
{
killMe
.
Dispose
();
}
catch
{
}
}
return
ConnectImpl
(()
=>
CreateMultiplexer
(
configuration
),
log
);
}
/// <summary>
/// Create a new ConnectionMultiplexer instance
/// </summary>
public
static
ConnectionMultiplexer
Connect
(
ConfigurationOptions
configuration
,
TextWriter
log
=
null
)
{
return
ConnectImpl
(()
=>
CreateMultiplexer
(
configuration
),
log
);
}
private
static
ConnectionMultiplexer
ConnectImpl
(
Func
<
ConnectionMultiplexer
>
multiplexerFactory
,
TextWriter
log
)
{
IDisposable
killMe
=
null
;
try
{
var
muxer
=
CreateMultiplexer
(
configuration
);
var
muxer
=
multiplexerFactory
(
);
killMe
=
muxer
;
// note that task has timeouts internally, so it might take *just over* the reegular timeout
var
task
=
muxer
.
ReconfigureAsync
(
true
,
false
,
log
,
null
,
"connect"
);
// note that task has timeouts internally, so it might take *just over* the regular timeout
// wrap into task to force async execution
var
task
=
Task
.
Factory
.
StartNew
(()
=>
{
return
muxer
.
ReconfigureAsync
(
true
,
false
,
log
,
null
,
"connect"
).
Result
;
});
if
(!
task
.
Wait
(
muxer
.
SyncConnectTimeout
(
true
)))
{
task
.
ObserveErrors
();
if
(
muxer
.
RawConfig
.
AbortOnConnectFail
)
{
throw
new
TimeoutException
(
);
throw
ExceptionFactory
.
UnableToConnect
(
"Timeout"
);
}
}
if
(!
task
.
Result
)
throw
ExceptionFactory
.
UnableToConnect
(
muxer
.
failureMessage
);
...
...
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
View file @
57f1c3b9
...
...
@@ -130,7 +130,7 @@ internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback)
CompletionTypeHelper
.
RunWithCompletionType
(
(
cb
)
=>
socket
.
BeginConnect
(
endpoint
,
cb
,
Tuple
.
Create
(
socket
,
callback
)),
(
ar
)
=>
EndConnectImpl
(
ar
),
CompletionType
.
Sync
);
connectCompletionType
);
}
catch
(
NotImplementedException
ex
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment