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

Client timeout doesn't work #1433

Open
olivasmaybell opened this issue Feb 20, 2025 · 1 comment
Open

Client timeout doesn't work #1433

olivasmaybell opened this issue Feb 20, 2025 · 1 comment

Comments

@olivasmaybell
Copy link

Describe the bug
Creating a client and connecting to a non-existent endpoint doesn't timeout as expected. It just hangs/cycles.

To Reproduce

from socketio import Client
sio = Client(engineio_logger=True)
print("attempting to connect...")
sio.connect(
    "http://localhost:7777",
    retry=5,
    wait=True,
    wait_timeout=1,
)
print("connected.")

I was testing this using a websocket transport, but that doesn't matter. I also increased the wait_timeout to 10, but that didn't seem to change anything. I don't see where the wait_timeout is being respected.

Expected behavior
I expect it to timeout as opposed to blocking indefinitely.

Logs

Attempting polling connection to http://localhost:7777/socket.io/?transport=polling&EIO=4
HTTP GET request to http://localhost:7777/socket.io/?transport=polling&EIO=4&t=1740072292.5999632 failed with error HTTPConnectionPool(host='localhost', port=7777): Max retries exceeded with url: /socket.io/?transport=polling&EIO=4&t=1740072292.5999632 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdcdb587d10>: Failed to establish a new connection: [Errno 111] Connection refused')).

This continues indefinitely, printing that error message about once per second.

@miguelgrinberg
Copy link
Owner

I think you are mixing up timeouts at different levels of the stack.

The wait_timeout that you are using is not a timeout for a low-level (ie. HTTP) connection. This is a timeout for the Socket.IO handshake, once the low-level connection is established. The reason for this timeout is that this handshake can take some time, depending on the application and the number of namespaces used. Here are the definitions of the wait and wait_timeout arguments, copied from the documentation:

  • wait – if set to True (the default) the call only returns when all the namespaces are connected. If set to False, the call returns as soon as the Engine.IO transport is connected, and the namespaces will connect in the background.
  • wait_timeout – How long the client should wait for the connection. The default is 1 second. This argument is only considered when wait is set to True.

Based on your description you are connecting to a non-existing endpoint. If you want non-default retry logic and timeouts at that level, then you have to define your own customized HTTP client session. See the http_session argument that is passed in the constructor of the Client object. Docs copied below for your convenience:

  • http_session – an initialized requests.Session object to be used when sending requests to the server. Use it if you need to add special client options such as proxy servers, SSL certificates, custom CA bundle, etc.

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

2 participants