Skip to content

Fix WebSocketClient close: tolerate WS_SEND broken pipe error #831

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhoushuo19
Copy link

Summary

When the server closes a WebSocket connection, calling .close() in curl_cffi >=0.11.1 raises a WS_SEND error with "Broken pipe".

This patch wraps .close() in a try/except block to suppress this specific non-critical error.

Traceback (most recent call last):
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/discord/gateway.py", line 172, in run
    await self.ws.close(4000)
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/discord/gateway.py", line 864, in close
    await self.socket.close(code, reason)
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/curl_cffi/requests/websockets.py", line 730, in close
    await self.send(msg, CurlWsFlag.CLOSE)
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/curl_cffi/requests/websockets.py", line 675, in send
    return await self.loop.run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/curl_cffi/curl.py", line 463, in ws_send
    self._check_error(ret, "WS_SEND")
  File "/home/ec2-user/miniconda3/envs/hunter/lib/python3.11/site-packages/curl_cffi/curl.py", line 154, in _check_error
    raise error
curl_cffi.curl.CurlError: Failed to WS_SEND, curl: (55) Send failure: Broken pipe. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

General Info

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue (please put issue # in summary).
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

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

Successfully merging this pull request may close these issues.

1 participant