Skip to content

Commit 838e3a0

Browse files
authored
fixed WebSocket disconnected (NRE) bug (#525)
- upon connecting to a WS endpoint, sometimes the connection can be lost prior to the subscribe messages being sent - check to make sure the WebSocket is still connected prior to sending each messageQueue
1 parent 8e2a808 commit 838e3a0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/ExchangeSharp/Utility/ClientWebSocket.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ public Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer, Canc
135135

136136
public Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken)
137137
{
138-
return webSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
138+
if (webSocket.State == WebSocketState.Open)
139+
return webSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
140+
else return Task.CompletedTask;
139141
}
140142
}
141143

0 commit comments

Comments
 (0)