Replies: 2 comments 3 replies
-
The Socket.IO client includes its own reconnection support. My guess is that the multiple connections happen because your own reconnection attempts interfere with the internal ones. If you want to use your own reconnection logic I suggest you turn off the client's own by passing |
Beta Was this translation helpful? Give feedback.
-
Hi @miguelgrinberg , I noticed an error on the server side: |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am designing the client-side of an application. I have access to the server code but I didn't write it myself so my understanding of it is limited. Both the client and the server use
python-socketio==5.4.0
. The client and the server are two docker containers which runs on the same machine.The server is storing some credentials. The client sends a GET request to the server to request the credentials. Then, the client waits to receive the credentials on the publish handler. After waiting for 15 seconds, the client forces a reconnection: it disconnects, it initializes a new
socketio.Client()
, register the namespaces, and start the connection.Here's the issue: the timeout occurs at least a few times a day. As a consequence, the connection is restarted a few times.
After this happens, the server seems to have multiple connections opened on its side. Is this an expected behavior? What may be happening here? Is it possible that the timeout happens because the server is unresponsive (or the connection has been lost) and as a consequence the client cannot effectively close the connection on the server? I believed the connection was managed by the library.
Here's my client code. Note that the only way to start the connection (using this code) is to call the
reconnect
method. The client connection is used by multiple threads. As you can see I implemented some mechanism to prevent multiple very-close-in-time reconnections (I originally believed there could be some race conditions). Also, to prevent race conditions, when emitting from the client, I always wait forsocket_client.connected
to beTrue
(seeemit
method below).socket_manager.py
I didn't write the server code. I am doing my best to understand how it works. There's some hierarchy involved, and the server code uses:
Flask-SocketIO==5.0.1
withpython-socketio==5.4.0
. The server code is a bit long, so I don't expect you to read it all. I am posting it here because I am not sure which part you would need. I am happy to provide more specific answers based on your suggestions.The server code counts the number of clients connected by looking at the attribute
_clients
of the base class. Also,SocketIOServerBaseMessageHandler
.SocketIOServerCredentialsHandler
extendsSocketIOServerOnlyNamespaceMessageHandler
which extendsSocketIOServerBaseMessageHandler
which extendsNamespace
(from flask_socketio import Namespace
).Could you provide any hint on what may be happening? Let me know if you need other information.
Beta Was this translation helpful? Give feedback.
All reactions