question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

4.4.10 release makes ws connection even when raising ConnectionRefusedError

See original GitHub issue

Since this is actually an separate issue, even though on the same topic, I’m creating a new issue for it.

Open browser inspector tool, go to network->ws, and you will see a websocket connection even when you raise the ConnectionRefusedError. It stays half-connected as you can see ping events, but aren’t able to send any messages. On trying to connect using the js client socket again after I login through http (flask-session server side setup), the client socket cannot be used to connect as it is still connected.

python

@socketio.on('connect')
def connect():
    # if not current_user.is_authenticated:
    raise ConnectionRefusedError()

js

import io from 'socket.io-client';
socket = io()

// this used to be hit when on python-socketio 4.3.1
socket.on('connect_error', function(error){
  console.log(error)
}
// this is now hit on 4.4.1
socket.on('error', function(error){
  console.log(error)
}

// on connect, disconnect ...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
miguelgrinbergcommented, Apr 20, 2020

This is actually the core of the problem I’m trying to solve. I haven’t looked specifically at the JS client yet, but yes, the idea is that the connection error should be invoked when the server declines a connection.

1reaction
acnebscommented, Apr 20, 2020

Right, that makes sense, thanks for the explanation.

The issue I’m having is that I don’t know where I’m supposed to handle the raised exception on the client-side (when using the JS client). Obviously the JS library isn’t your purview, but one generally hopes that the various SocketIO libs should seamlessly interoperate with each other. But when I read through the python-socketio client docs, I couldn’t seem to find much guidance there either for this situation.

In the python-socketio client, is it the connect_error() handler that handles both the return False method and the raise ConnectionRefusedError("info") method for short-circuiting a connection? And am I right in thinking that the args in connect_error() are the args passed into the ConnectionRefusedError?

Because when using the JS client lib, my error handler is triggered when I return False server-side in both 4.3.x and 4.5.x. Meanwhile, neither my client-side error nor my connect_error handlers are being triggered when I call raise ConnectionRefusedError() on the server side (in both mentioned versions). The JS client has “support” for connect_errors, it just seems like raising an exception in the python-socketio server isn’t doing what the JS client expects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >
The WebSocket API (WebSockets) - Web APIs - MDN Web Docs
desktop desktop Chrome Edge WebSocket Full support. Chrome4. Toggle history Full support. Edge12. Toggl... WebSocket() constructor Full support. Chrome4. Toggle history Full support. Edge12. Toggl...
Read more >
Troubleshooting Connection Issues to Neo4j
When I try to use regular HTTP and port 7474 in Google Chrome, I get the "ServiceUnavailable: WebSocket connection failure" error, even though...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found