Skip to content

io.emit causes 4undefined frame #2590

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

Closed
nitin02 opened this issue Jun 19, 2016 · 6 comments
Closed

io.emit causes 4undefined frame #2590

nitin02 opened this issue Jun 19, 2016 · 6 comments

Comments

@nitin02
Copy link

nitin02 commented Jun 19, 2016

The nodejs servers are set up on AWS EC2 instances with Nginx as the primary load balancer. I'm implementing a the concept of "rooms" with socket.io 's redis adapter and found no work around for this issue.

I can see from my chrome's "network" tab in debug mode that, it switches to websocket. In the Frame's tab of the web socket, I can see all the information sent to and back from the nodejs server.

Any operation with socket.emit is proper and returns the proper object as 4["actual_content"] frame and is received by the client but any operation with io object (all operation done with io) returns a 4undefined frame.

Please note that, there seems to be no code issue as the same setup works perfectly when implemented locally on my machine.

Thank you for your help.

@MasterJames
Copy link

MasterJames commented Jun 19, 2016

I'm thinking you should simplify the problem to a code sample you're comfortable with posting.
If you use io.on "connection" it's the handler you pass that can see its argument the socket for emit etc. So it's probably the expected behaviour for io.on to return undefined as a result, no?
I'm sure you know that so I must not be seeing clearly in this moment.

Are you fully updated? Talking about Engine.IO ?

When you require ("socket.io")( do you pass a port? ) or arguments?
Call attach?

@nitin02
Copy link
Author

nitin02 commented Jun 19, 2016

Simplified, this is what I am doing,

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

http.listen(3000, function(){
  console.log('listening on *:3000');
});

The below code works, I am able send back to the client using the socket object.

io.on('connection', function(socket){
  socket.join('news');
  socket.broadcast.emit('update', 'hello world');
// or any type of operation with socket works, for example: socket.emit('news', 'hello world' );
});

However, the below causes 4undefined frame.

io.to('news').emit('update', 'hello world');

or any type of operation using the io object,

For example:

io.sockets.emit('update', 'hello world');
io.emit('update', 'hello world');

I've tried using the latest version of socket.io (v1.4.6). Do note that the same code works locally.

@MasterJames
Copy link

MasterJames commented Jun 20, 2016

Do you put the "to" inside the on 'connection' ?
http://socket.io/docs/server-api/#socket#in(room:string):socket
no of course not. Maybe this is helpful if it's originating from some client and they don't need to see it themselves?
socket.broadcast.to (oh you are using that, right)
as opposed to
socket.emit('update', {room: 'news', mssg: 'update world'});

@MasterJames
Copy link

MasterJames commented Jun 20, 2016

Does it change if you force long-polling?
io.set('transports', ['jsonp-polling']);

or maybe

io.configure(function () { 
      io.set("transports", ["xhr-polling"]); 
      io.set("polling duration", 10); 
    });

Not as a solution just checking for possible reasons.

I'm guessing some port is blocked. Maybe try a different port like 4321? (oh right 3000 how about 80 then?)
Who is the provider?

Can you access this from both ends?
http://www.websocket.org/echo.html

Heavier document saying Proxies can cause problems etc.
https://www.infoq.com/articles/Web-Sockets-Proxy-Servers

@MasterJames
Copy link

MasterJames commented Jun 20, 2016

Well if your on AWS using ELB this might be useful. It might be what's happening wherever you are hosting.
https://www.built.io/blog/2014/11/websockets-on-aws-elb/

Another link that might help
http://stackoverflow.com/questions/22745020/testing-if-client-can-connect-to-websockets-with-port-80-443-843

This Chrome plugin might be useful too
https://chrome.google.com/webstore/detail/socketio-tester/cgmimdpepcncnjgclhnhghdooepibakm?hl=en

You can also do this in the browser for extra debugging info.
localStorage.debug = '*'
from
http://socket.io/docs/logging-and-debugging/
gives more detail like...

update: good bye world 6
socket.io.js:2708 socket.io-client:manager writing packet {"type":2,"data":["got",{"mssg":"update"}],"options":{"compress":true},"nsp":"/"} +1ms
socket.io.js:2708 socket.io-parser encoding packet {"type":2,"data":["got",{"mssg":"update"}],"options":{"compress":true},"nsp":"/"} +2ms
socket.io.js:2708 socket.io-parser encoded {"type":2,"data":["got",{"mssg":"update"}],"options":{"compress":true},"nsp":"/"} as 2["got",{"mssg":"update"}] +1ms
socket.io.js:2708 engine.io-client:socket flushing 1 packets in socket +19ms
socket.io.js:2708 engine.io-client:socket writing ping packet - expecting pong within 60000ms +11s
socket.io.js:2708 engine.io-client:socket flushing 1 packets in socket +0ms
socket.io.js:2708 engine.io-client:socket socket receive: type "pong", data "undefined" +4ms

Then you can get a break point into the stack at some point like the log socket.io.js:2708 and try to trace in there that way.

I guess you could dig further by trying this snippet in Engine.IO the Client code.
https://github.com/socketio/engine.io-client

@nitin02
Copy link
Author

nitin02 commented Jun 20, 2016

Thank you for your exhaustive and wonderful list of solutions and tips.

However, After much search I was able to pin-point the error to the issue below by printing socket.id and socket.client.id,

#2405
#2491

This seems to be a known consequence of the latest versions of socket.io. This issue is still open (2405) and will be resolved in the next release (maybe). They should at least point this out somewhere, considering that this a serious issue.

So, Manually degrading socket.io 1.3.* did the trick. All is working well.

(On a side note, I am still puzzled as to why only operations on socket worked properly previously as the above issue should have broken that functionality too. Weird!)

Thank you for your time.

@nitin02 nitin02 closed this as completed Jun 20, 2016
gmazlami added a commit to probr-uzh/probr-analysis that referenced this issue Oct 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants