Replies: 11 comments
-
This can be a race condition. If you emit on a namespace that is not connected you will get the bad namespace error. After a disconnection and reconnection, how do you know when it is safe to emit? If you are just emitting from a different thread without knowing if you are connected or not then this error can appear and the correct way to handle would be to catch it and retry a bit later, assuming you do not want your app to crash. |
Beta Was this translation helpful? Give feedback.
-
Hm, if I understand you correctly then you are recommending that I catch this error and retry again some time later? |
Beta Was this translation helpful? Give feedback.
-
That's exactly what this package is doing. It blocks the emit and prevents it from happening. This is done by raising an exception. I'm not sure what other way you are thinking this can be done. Ignoring the emit and keep going is a terrible idea, you do not want this to fail silently. |
Beta Was this translation helpful? Give feedback.
-
Sorry, for the confusion. What I meant is that I got an BadNamespaceError which doesnt tell me what really happens. Also, emit could store the message (and of course send a log message if it does) and send it when the connection is reestablished. Basically what you told me to do? |
Beta Was this translation helpful? Give feedback.
-
We can argue about my choice of words, but really the "bad namespace" error means that you are emitting on a namespace that is not connected. Also note that when there is a disconnection, the application is notified. Your application is calling the emit function regardless of being told you aren't connected anymore.
This package has no way to know what the application wants to do. As I indicated above, you are emitting a packet after being notified that you are not connected anymore, so I don't think it is the job of this package to handle the application's mistake. |
Beta Was this translation helpful? Give feedback.
-
Running into this same issue. @miguelgrinberg Problem is that there's no way to "reconnect" the namespace AFAIK. I'm trying to test for this, but there doesn't seem to be a proper solution. It just fails with a "already connected error". |
Beta Was this translation helpful? Give feedback.
-
@jimklo Why are your namespaces getting disconnected? The normal case is when the whole connection is lost, at which point the client will attempt to reconnect, and this includes reconnecting all the namespaces. |
Beta Was this translation helpful? Give feedback.
-
@miguelgrinberg That's a very good question, that I don't have an answer. I have a suspicion that because the size of the the messages are pretty large (~7000x12 dataframe converted to a dict)... I suspect the PING/PONG of the protocol isn't functioning quite right when the server stalls on receiving the large dataframe. |
Beta Was this translation helpful? Give feedback.
-
@jimklo the ping/pong packets are also global to the connection, so they would cause all namespaces to go at the same time, along with the transport. Upon reconnecting all the namespaces should be reconnected together. My question is this. Is your application being notified that the namespace(s) was disconnected? If it is, and you call emit after that, you are going to get a BadNamespaceError and that is the way I expect things to work. If you are telling me that you are not receiving the disconnect event, and out of the blue an emit call fails with this error then we have a problem, but I don't get the impression this is what you are reporting. |
Beta Was this translation helpful? Give feedback.
-
@miguelgrinberg no the application is NOT being notified that the namespace is being disconnected. I tried adding something like:
and that never gets called... however if i get the BadNamespaceError as well as the namespace disconnected error when I try to
It's a little tricky to share the exact code to reproduce... However I think I might be able to cook up a reasonable facsimile. It's also possible that this is an issue with the server side which leverages a derivative project, |
Beta Was this translation helpful? Give feedback.
-
@jimklo the disconnect handlers are specific to the namespace. The code that you show above will listen for disconnects on |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I create a Websocket connection and sometimes (for reasons currently unknown) this connection gets closed. SocketIO then tries to recreate the connection which is really good. But unfortunatelly it doestn care about my registered namespaces and so after the connection is reestablished I get an BadNamespaceError when emitting something.
Version is 5.1.0
If I see this correctly _handle_eio_disconnect is called which removes all namespaces and _handle_reconnect doesnt restore them?
Or do we something wrong? Our implementation is a bit special as we create all events dynamically. Ah and we overwrite the default namespace, so our custom namespace is on /
If needed I can provide more examples and also a log (which I doesnt have currently, these reconnects are very random).
Thanks in advance and thank you for your great work!
Beta Was this translation helpful? Give feedback.
All reactions