Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 844da9e

Browse files
committed
Ensure socket != null after TryConnectIfNeeded()
1 parent 1336536 commit 844da9e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/ServiceStack.Redis/RedisNativeClient_Utils.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private void Connect()
155155
ServerVersionNumber = RedisConfig.AssumeServerVersion.GetValueOrDefault(0);
156156
if (ServerVersionNumber <= 0)
157157
{
158+
{
158159
var parts = ServerVersion.Split('.');
159160
var version = int.Parse(parts[0]) * 1000;
160161
if (parts.Length > 1)
@@ -247,7 +248,7 @@ internal bool AssertConnectedSocket()
247248
socket = null;
248249

249250
DeactivatedAt = DateTime.UtcNow;
250-
var message = "" + Host + ":" + Port;
251+
var message = Host + ":" + Port;
251252
var throwEx = new RedisException(message, ex);
252253
log.Error(throwEx.Message, ex);
253254
throw throwEx;
@@ -292,8 +293,8 @@ private RedisResponseException CreateResponseError(string error)
292293

293294
if (!RedisConfig.DisableVerboseLogging)
294295
{
295-
var safeLastCommand = string.IsNullOrEmpty(Password)
296-
? lastCommand
296+
var safeLastCommand = string.IsNullOrEmpty(Password)
297+
? lastCommand
297298
: (lastCommand ?? "").Replace(Password, "");
298299

299300
if (!string.IsNullOrEmpty(safeLastCommand))
@@ -503,9 +504,9 @@ private int SafeReadByte()
503504
return Bstream.ReadByte();
504505
}
505506

506-
protected T SendReceive<T>(byte[][] cmdWithBinaryArgs,
507-
Func<T> fn,
508-
Action<Func<T>> completePipelineFn = null,
507+
protected T SendReceive<T>(byte[][] cmdWithBinaryArgs,
508+
Func<T> fn,
509+
Action<Func<T>> completePipelineFn = null,
509510
bool sendWithoutRead = false)
510511
{
511512
var i = 0;
@@ -519,6 +520,9 @@ protected T SendReceive<T>(byte[][] cmdWithBinaryArgs,
519520
{
520521
TryConnectIfNeeded();
521522

523+
if (socket == null)
524+
throw new RedisRetryableException("Socket is not connected");
525+
522526
if (i == 0) //only write to buffer once
523527
WriteCommandToSendBuffer(cmdWithBinaryArgs);
524528

@@ -552,7 +556,7 @@ protected T SendReceive<T>(byte[][] cmdWithBinaryArgs,
552556
catch (Exception outerEx)
553557
{
554558
var retryableEx = outerEx as RedisRetryableException;
555-
if (retryableEx == null && outerEx is RedisException
559+
if (retryableEx == null && outerEx is RedisException
556560
|| outerEx is LicenseException)
557561
{
558562
ResetSendBuffer();

0 commit comments

Comments
 (0)