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
First message never gets sent #2273
Comments
I'm having the exact same issue. Adding a 250ms delay before sending the first message seems to make it go through. |
Hi, thanks for your report. Can you post your code to reproduce the issue? |
Sure thing. My client code looks like this:
I then run:
The code above with fail about 50% of the time. However, if I change the login function to:
Then I'm able to get 100% success rate. I have confirmed that it's not a race condition issue. The connection always succeeds first before the login method is called. So by the time I emit the login event, the connection is definitely established. Looking at the Frames in the Network tab of the Chrome dev tools, I see that without the timeout, the 'login' event frame doesn't always get published. |
@globexdesigns thanks, but somehow I couldn't reproduce. It worked fine to me. |
Digging into this a bit more, I believe something strange is going on with the
Why is UPDATE: I was able to solve my problem by changing:
By default |
I have encountered the same problem: the first message is not sent, but all messages after are. Setting transports to |
@EvNaverniouk please see https://github.com/socketio/engine.io#goals for details about long-polling / Websocket transports Using Related: #2485 |
As commented here, I couldn't reproduce: https://github.com/darrachequesne/socket.io-fiddle/tree/issue/lost-message Is is related to a given browser? |
@eneroth Could you please provide the code you used (which produced the log below)? It seems Did you use a global broadcast?
In that case, the for (var id in self.sids) {
if (self.sids.hasOwnProperty(id)) {
if (~except.indexOf(id)) continue;
socket = self.nsp.connected[id];
if (socket) socket.packet(encodedPackets, packetOpts);
}
} Those values are set there: Socket.prototype.onconnect = function(){
debug('socket connected - writing packet');
this.join(this.id); // => update the sids values in the adapter
this.packet({ type: parser.CONNECT });
this.nsp.connected[this.id] = this;
}; Which is called there: socket.onconnect();
if (fn) fn();
// fire user-set events
self.emit('connect', socket);
self.emit('connection', socket); A simple race condition here? |
It seems I was able to (kind of) reproduce the issue here, by changing the following lines: Socket.prototype.onconnect = function(){
debug('socket connected - writing packet');
this.nsp.connected[this.id] = this;
//this.join(this.id);
setTimeout(() => this.join(this.id), 10);
this.packet({ type: parser.CONNECT });
}; The browser gets:
@eneroth could you confirm that behaviour? |
Same issue here, please find a fix! update: rather than applying a timeout, process.nextTick seems a better solution |
@vinz243 Which version of socket.io are you using? Could you provide some code please? |
I have socketio 1.7.3. It's been a week sorry I'm not sure the exact fix, maybe this code on server: emitter.on(['server', 'ping'], () => {
process.nextTick(() => {
return emitter.emit(['client', 'pong']);
})
}); |
@darrachequesne this is a quite large project and I have no idea how i fixed the issue sorry |
Any ideas? Same issue
what i've pointed out is that at emmititing 'immediate' event the socket.client.Client.conn.socket.upgraded is false, but after 1.5s that is true, and all works just fine |
For some reason, whenever a new connection is established, the first message I send always seems to go silently ignored. I switched on logging on the Node side, and this is the output:
It seems like the first message (the bullshit-message, as I've come to call it in testing) is encoded, but never actually sent off to the client. What is going on here?
On client:
The text was updated successfully, but these errors were encountered: