-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AbortController but for Websockets #57
Comments
The WebSocket The proposed WebSocketStream API uses AbortController for cancelling the handshake already. We are unlikely to add this to the WebSocket API because it can be easily emulated with a function like function AbortableWebSocket(url, signal) {
signal.throwIfAborted();
const ws = new WebSocket(url);
const abortHandler = () => ws.close();
signal.addEventListener('abort', abortHandler);
ws.addEventListener('open',
() => signal.removeEventListener('abort', abortHandler));
return ws;
} |
ok that's nice @ricea , thank you |
You meant ws.addEventListener('close', () => signal.removeEventListener('abort', abortHandler));
// ^^^^^ right? |
.... waiting for Mr Rice |
No, my use of the While it is tidy to remove the event listener when the WebSocket is closed, it's not strictly necessary, as calling |
Oh I didn't read that closely enough, thanks for the re-emphasis:
I don't think that's particularly useful. When I want to discard/cancel/abort a WebSocket connection, I don't care about its current status. I want it torn down, regardless whether the handshake has already been completed or not. (And what about race conditions where the handshake completion has already been received but not yet processed when the signal is aborted?) Sure it's also nice to have extra methods for more precise control, like
It's necessary to avoid memory leaks, as the abort signal may be reused and around for much longer than the web socket. |
The
Race conditions are an issue, yes, particularly if the main thread is busy.
True. |
What is the issue with the WebSockets Standard?
We can abort outgoing HTTP requests
We should be able to abort outgoing WS connection requests are pending
See:
https://stackoverflow.com/questions/77971834/how-to-cleanly-close-abort-a-webscoket-connection-before-it-connects
The text was updated successfully, but these errors were encountered: