connect() sometimes fails to fire error event when failing to connect
See original GitHub issueAttempt to connect to a peer that doesn’t exist, and listen for the error event.
Expected: should fire the error event.
Observed: sometimes it does, sometimes NOTHING. It fails to connect (which is expected), but it does not fire the error event either. No open, close or error event, nothing.
Example code:
var peer;
var conn;
var otherId="whatever";
var connected=false;
$(function(){
peer=new Peer({
host: 'example.com',
port: 9000,
key: 'xxx'
});
startConnect();
});
function startConnect() {
connected=false;
$("#connection-info").html("Connecting...");
conn=peer.connect(otherId);
conn.on('open', function(){
console.log("connection open");
initDataConnection();
})
conn.on('close', function(){
console.log("Connection closed");
connected=false;
startConnect();
});
conn.on('error', function() {
connected=false;
$("#connection-info").html("Connection error.");
console.log("connection error ");
});
}
function initDataConnection() {
connected=true;
conn.on('data', function(data){
console.log("Received: "+data);
});
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Socket.io Client Fire Event if Can't connect to server
I'm running a simple node.js server on Amazon EC2 that is running socket.io for me. I'm working on a chrome extension that sends...
Read more >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 >Troubleshoot common issues with triggers - Power Automate
This error means that Power Automate tried multiple times to establish a connection to register the trigger and failed.
Read more >Let It Crash: Best Practices for Handling Node.js Errors on ...
Let's say we have a server running. It's receiving requests and establishing connections with clients. But what happens if the process crashes?
Read more >Node.js Error Handling Best Practices: Ship With Confidence
throw new Error('database failed to connect');. That may sound pretty overwhelming. For simplicity, let's break it down. Two distinct things are ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Sorry for the previous deleted comments. I had some errors in my test code.
Are there any news? I still confirm the issue and I can’t find a precise pattern. This bug is VERY SERIOUS, as not being able to reliably detect when a connection cannot be established or is lost renders peerjs totally unusable.
Here’s a recap:
connect()errorevent on both the Peer object itself and the DataConnection object returned byconnect. I also listen to thecloseevent on the DataConnection object.errorevent is fired by the Peer objectcloseevent is fired either by the DataConnection object.connect(), and neither theopennor theerrorevent are fired.The way I systematically reproduce the issue is as follows:
errorevent either in the Peer or the DataConnection object, or acloseevent on the DataConnection, I set a timeout and start all over, creating a new Peer and trying to connect it to the remote, whose id is known.openevent is fired as expectedcloseevent as expected and starts retrying.errorevent as expected and keeps retryingAt this point, it would be expected that the connection from the local Peer succeeds. Instead, it neither succeeds neither triggers an error. Neither the
openevent (on DataConnection) nor theerrorevent (on the Peer) are fired.Should be fixed in 1.0.4+