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

Commit 910530e

Browse files
committed
Add disposed connection check in ReadLine + SafeReadByte
1 parent 5530982 commit 910530e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ServiceStack.Redis/RedisNativeClient_Utils.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Net;
1919
using System.Net.Security;
2020
using System.Net.Sockets;
21+
using System.Runtime.CompilerServices;
2122
using System.Security.Authentication;
2223
using System.Security.Cryptography;
2324
using System.Security.Cryptography.X509Certificates;
@@ -248,6 +249,8 @@ public virtual void OnConnected()
248249

249250
protected string ReadLine()
250251
{
252+
AssertNotDisposed();
253+
251254
var sb = StringBuilderCache.Allocate();
252255

253256
int c;
@@ -555,8 +558,17 @@ public void ResetSendBuffer()
555558
}
556559
}
557560

561+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
562+
void AssertNotDisposed()
563+
{
564+
if (Bstream == null)
565+
throw new ObjectDisposedException($"Redis Client {ClientId} is Disposed");
566+
}
567+
558568
private int SafeReadByte(string name)
559569
{
570+
AssertNotDisposed();
571+
560572
if (log.IsDebugEnabled && RedisConfig.EnableVerboseLogging)
561573
logDebug(name + "()");
562574

0 commit comments

Comments
 (0)