Fixed read buffer memory leak
@@ -80,6 +80,8 @@ namespace MiningCore.JsonRpc
var sb = new StringBuilder();
tcp.OnRead((handle, buffer) =>
+ {
+ using (buffer)
{
// onAccept
var data = buffer.ReadString(Encoding.UTF8);
@@ -108,6 +110,7 @@ namespace MiningCore.JsonRpc
observer.OnError(new InvalidDataException($"[{ConnectionId}] Incoming message exceeds maximum length of {MaxRequestLength}"));
}
}
+ }
}, (handle, ex) =>
{
// onError
@@ -120,6 +123,10 @@ namespace MiningCore.JsonRpc
// release handles
handle.CloseHandle();
sendQueueDrainer.CloseHandle();
+ sendQueueDrainer.UserToken = null;
+
+ sendQueue = null;
+ sb = null;
});
return Disposable.Create(() =>
@@ -183,12 +190,11 @@ namespace MiningCore.JsonRpc
{
try
{
- byte[] data;
var tcp = (Tcp) handle.UserToken;
- while (tcp?.IsValid == true && !tcp.IsClosing && tcp.IsWritable &&
- sendQueue.TryDequeue(out data))
+ if (tcp?.IsValid == true && !tcp.IsClosing && tcp.IsWritable && sendQueue != null)
{
+ while (sendQueue.TryDequeue(out var data))
tcp.QueueWrite(data);
}
}
