Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdks/csharp/src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ public void Disconnect()
{
webSocket.Close();
}
else
{
webSocket.Abort(); // forceful during connecting
}

_parseCancellationTokenSource.Cancel();
}
Expand Down
25 changes: 25 additions & 0 deletions sdks/csharp/src/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,31 @@ public Task Close(WebSocketCloseStatus code = WebSocketCloseStatus.NormalClosure
return Task.CompletedTask;
}

/// <summary>
/// Forcefully abort the WebSocket connection. This terminates any in-flight connect/receive/send
/// and ensures the server-side socket is torn down promptly. Prefer Close() for graceful shutdowns.
/// </summary>
public void Abort()
{
#if UNITY_WEBGL && !UNITY_EDITOR
// WebGL plugin does not expose an Abort; fall back to a best-effort close if connected.
if (_isConnected && _webglSocketId >= 0)
{
WebSocket_Close(_webglSocketId, (int)WebSocketCloseStatus.NormalClosure, "Aborting connection.");
_isConnected = false;
}
#else
try
{
Ws?.Abort();
}
catch
{
// Intentionally swallow; Abort is best-effort.
}
#endif
}

private Task? senderTask;
private readonly ConcurrentQueue<ClientMessage> messageSendQueue = new();

Expand Down
Loading