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
5fb3279a
Commit
5fb3279a
authored
Jul 31, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `isInitialConnect` override to make sure we record failure in the initial connect
parent
3cd098b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
18 deletions
+25
-18
ConnectionFailedErrors.cs
StackExchange.Redis.Tests/ConnectionFailedErrors.cs
+19
-7
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+6
-11
No files found.
StackExchange.Redis.Tests/ConnectionFailedErrors.cs
View file @
5fb3279a
using
System
;
using
System.Security.Authentication
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
...
...
@@ -32,10 +33,16 @@ public async Task SSLCertificateValidationError(bool isCertValidationSucceeded)
if
(!
isCertValidationSucceeded
)
{
//validate that in this case it throws an certificatevalidation exception
var
ex
=
Assert
.
Throws
<
RedisConnectionException
>(()
=>
connection
.
GetDatabase
().
Ping
());
var
rde
=
(
RedisConnectionException
)
ex
.
InnerException
;
Assert
.
Equal
(
ConnectionFailureType
.
AuthenticationFailure
,
rde
.
FailureType
);
Assert
.
Equal
(
"The remote certificate is invalid according to the validation procedure."
,
rde
.
InnerException
.
Message
);
var
outer
=
Assert
.
Throws
<
RedisConnectionException
>(()
=>
connection
.
GetDatabase
().
Ping
());
Assert
.
Equal
(
ConnectionFailureType
.
UnableToResolvePhysicalConnection
,
outer
.
FailureType
);
Assert
.
NotNull
(
outer
.
InnerException
);
var
inner
=
Assert
.
IsType
<
RedisConnectionException
>(
outer
.
InnerException
);
Assert
.
Equal
(
ConnectionFailureType
.
AuthenticationFailure
,
inner
.
FailureType
);
Assert
.
NotNull
(
inner
.
InnerException
);
var
innerMost
=
Assert
.
IsType
<
AuthenticationException
>(
inner
.
InnerException
);
Assert
.
Equal
(
"The remote certificate is invalid according to the validation procedure."
,
innerMost
.
Message
);
}
else
{
...
...
@@ -80,15 +87,20 @@ public void SocketFailureError()
options
.
Ssl
=
true
;
options
.
Password
=
""
;
options
.
AbortOnConnectFail
=
false
;
var
ex
=
Assert
.
Throws
<
RedisConnectionException
>(()
=>
options
.
ConnectTimeout
=
1000
;
var
outer
=
Assert
.
Throws
<
RedisConnectionException
>(()
=>
{
using
(
var
muxer
=
ConnectionMultiplexer
.
Connect
(
options
))
{
muxer
.
GetDatabase
().
Ping
();
}
});
var
rde
=
(
RedisConnectionException
)
ex
.
InnerException
;
Assert
.
Equal
(
ConnectionFailureType
.
SocketFailure
,
rde
.
FailureType
);
Assert
.
Equal
(
ConnectionFailureType
.
UnableToResolvePhysicalConnection
,
outer
.
FailureType
);
Assert
.
NotNull
(
outer
.
InnerException
);
var
inner
=
Assert
.
IsType
<
RedisConnectionException
>(
outer
.
InnerException
);
Assert
.
Equal
(
ConnectionFailureType
.
UnableToConnect
,
inner
.
FailureType
);
}
#if DEBUG // needs AllowConnect, which is DEBUG only
[
Fact
]
...
...
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
5fb3279a
...
...
@@ -159,7 +159,7 @@ internal async void BeginConnectAsync(TextWriter log)
catch
(
ObjectDisposedException
)
{
bridge
.
Multiplexer
.
LogLocked
(
log
,
"(socket shutdown)"
);
try
{
Error
(
);
}
try
{
RecordConnectionFailed
(
ConnectionFailureType
.
UnableToConnect
,
isInitialConnect
:
true
);
}
catch
(
Exception
inner
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
inner
.
Message
);
...
...
@@ -168,7 +168,7 @@ internal async void BeginConnectAsync(TextWriter log)
catch
(
Exception
outer
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
outer
.
Message
);
try
{
Error
(
);
}
try
{
RecordConnectionFailed
(
ConnectionFailureType
.
UnableToConnect
,
isInitialConnect
:
true
);
}
catch
(
Exception
inner
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
inner
.
Message
);
...
...
@@ -290,13 +290,13 @@ public Task FlushAsync()
return
Task
.
CompletedTask
;
}
public
void
RecordConnectionFailed
(
ConnectionFailureType
failureType
,
Exception
innerException
=
null
,
[
CallerMemberName
]
string
origin
=
null
)
public
void
RecordConnectionFailed
(
ConnectionFailureType
failureType
,
Exception
innerException
=
null
,
[
CallerMemberName
]
string
origin
=
null
,
bool
isInitialConnect
=
false
)
{
Exception
outerException
=
innerException
;
IdentifyFailureType
(
innerException
,
ref
failureType
);
if
(
_ioPipe
!=
null
)
// if *we* didn't burn the pipe: flag it
if
(
_ioPipe
!=
null
||
isInitialConnect
)
// if *we* didn't burn the pipe: flag it
{
if
(
failureType
==
ConnectionFailureType
.
InternalFailure
)
OnInternalError
(
innerException
,
origin
);
...
...
@@ -1133,7 +1133,7 @@ internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, Soc
}
catch
(
AuthenticationException
authexception
)
{
RecordConnectionFailed
(
ConnectionFailureType
.
AuthenticationFailure
,
authexception
);
RecordConnectionFailed
(
ConnectionFailureType
.
AuthenticationFailure
,
authexception
,
isInitialConnect
:
true
);
bridge
.
Multiplexer
.
Trace
(
"Encryption failure"
);
return
false
;
}
...
...
@@ -1154,17 +1154,12 @@ internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, Soc
}
catch
(
Exception
ex
)
{
RecordConnectionFailed
(
ConnectionFailureType
.
InternalFailure
,
ex
);
// includes a bridge.OnDisconnected
RecordConnectionFailed
(
ConnectionFailureType
.
InternalFailure
,
ex
,
isInitialConnect
:
true
);
// includes a bridge.OnDisconnected
bridge
.
Multiplexer
.
Trace
(
"Could not connect: "
+
ex
.
Message
,
physicalName
);
return
false
;
}
}
internal
void
Error
()
{
RecordConnectionFailed
(
ConnectionFailureType
.
SocketFailure
);
}
private
void
MatchResult
(
RawResult
result
)
{
var
muxer
=
BridgeCouldBeNull
?.
Multiplexer
;
...
...
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