Skip to content
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

close websocket properly even on error #39

Open
crotwell opened this issue Sep 13, 2022 · 1 comment
Open

close websocket properly even on error #39

crotwell opened this issue Sep 13, 2022 · 1 comment

Comments

@crotwell
Copy link

If a websocket datalink client sends a command that results in an error, a ERROR datalink packet is sent back with a reason, which is helpful. But the ringserver also closes the connection without going through the websocket close handshake, ie sending a CLOSE frame and waiting for the corresponding CLOSE response.

In clients.c about line 404 there is code to close the regular socket:

  /* Close client socket */
  if (cinfo->socket)
  {
    shutdown (cinfo->socket, SHUT_RDWR);
    close (cinfo->socket);
    cinfo->socket = 0;
  }

but as far as I can see no corresponding code to close a websocket nicely. It would be nice if the websocket could be closed gracefully even in the case of errors.

Docs on CLOSE are here:
https://www.rfc-editor.org/rfc/rfc6455#section-5.5.1

@crotwell
Copy link
Author

This also occurs on when ringserver does an idle close.

ringserver logs:

Wed Aug 14 12:49:11 2024 - Closing idle client connection: localhost
Wed Aug 14 12:49:11 2024 - Client disconnected: localhost

but my python websocket client shows exception:

  File "/Users/crotwell/Code/seis/simpledali/src/simpledali/websocketdali.py", line 67, in parseResponse
    response = await self.ws.recv()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simpledali_dev/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 568, in recv
    await self.ensure_open()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/simpledali_dev/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant