Google App Engine - socket.io throws errors before successfully connect - node.js

Ok so... For a while web sockets have been implemented in the GAE flex environment.
I've got an app deployed there and everything works "sorta" fine except that sometimes
When Connecting or
After a random disconnect and it tries to reconnect
I get a couple of these errors:
POST https://XXX.appspot.com/socket.io/?EIO=3&transport=polling&t=N00Ml-1&sid=XuKv8-6R2TZrIERGAAAO 400
WebSocket connection to 'wss://XXX.appspot.com/socket.io/?EIO=3&transport=websocket&sid=XuKv8-6R2TZrIERGAAAO' failed: WebSocket is closed before the connection is established
GET https://XXX.appspot.com/socket.io/?EIO=3&transport=polling&t=N00Ml-2&sid=XuKv8-6R2TZrIERGAAAO 400
I've googled a lot and tried a lot of the stuff suggested to people that had similar issues (most of them BEFORE GAE introduced websocket support).
After a couple of these errors it just connects and everything is fine... I've tried forcing transport as websocket on the client side but it doesn't seem to change anything.
Is there any fix? Should i just change cloud provider?
Not posting any code since it's the basic socket.io nodejs implementation, in fact I've tested with an empty basic implementation and it's the same thing, my best guess is they havn't implemented the load balancer correctly? Anybody has these issues? Should i go aws instead?

I managed to fix this... I've posted on the socket.io github issues
https://github.com/socketio/socket.io/issues/3543
And here's a link to a better explanation
https://github.com/socketio/socket.io/issues/3612#issuecomment-656667871

Related

Socket.io - invalid HTTP status code on SOME browsers

Just after a few weeks of working fine, our Socket.io started spewing errors on some browsers. I've tried updated to the latest Socket.io version, I've tried our setup on different machines, I've tried all sorts of machines, it seems to work on most browsers with no clear pattern of which work.
These errors appear on a second interval:
OPTIONS https://website.com/socket.io/?EIO=2&transport=polling&t=1409760272713-52&sid=Dkp1cq0lpKV75IO8AdA3 socket.io-1.0.6.js:2
XMLHttpRequest cannot load https://website.com/socket.io/?EIO=2&transport=polling&t=1409760272713-52&sid=Dkp1cq0lpKV75IO8AdA3. Invalid HTTP status code 400
We're behind Amazon's ELB, Socket.io on polling because the ELB router doesn't support WebSockets.
I found the problem that has been causing this, and it's is really unexpected...
This problem comes from using load balanced services like AWS ELB (independent EC2 should be fine though) and Heroku, their infrastructure doesn't support Socket.io features fully. AWS ELB flat out won't support WebSockets, and Heroku's router is trash for Socket.io, even in conjunction with socket.io-redis.
The problem is hidden when you use a single server, but as soon you start clustering, you will get issues. A single Heroku dyno on my application worked fine, and then the problems started appearing in production out of development, when we weren't using more than one server. We tried on ELB with sticky-load balance and even then, we still had the same issues.
When socket.io returns 400 errors, in this case it was saying "This session doesn't exist and you never completed the handshake", because you completed the handshake on a different server in your cluster.
The solution for me was just dedicating an EC2 instance for my web app to handle Socket.io.

Browser, behind Squid, can't establish connection to socket.io websockets transport

My problem is simple to explain but not so simple to fix I think since I haven't found a solution yet.
I'm developing an API. The backend is developed using NodeJs and Socket.Io. Everything works perfect but the issue arises when I'm on a net that's behind a firewall, Squid in this case. It is the browser who is behind the firewall not the server (NodeJs).
The thing is that I get this error:
WebSocket connection to 'ws://mydomain.com/socket.io/1/websocket/vN8hWt_EjV0Z5P5-GwrW' failed: Unexpected response code: 502 (socket.io.js:2)
and I don't know how to the browser can skip Squid.

Node.js and Socket.IO Not Responding in Some Servers

I have simple Node.js and Socket.IO app running on Nodejitsu. The App is running perfectly from home and some other Internet services but not working from my work!
Here is the error Message which I am getting
The connection to ws://behseini-socketproject.jit.su/socket.io/1/websocket/QtVm6E79WwGLwBVjN7el was interrupted while the page was loading.
this.websocket = new Socket(this.prepareUrl() + query);
socket.io.js (line 2371)
GET http://behseini-socketproject.jit.su/socket.io/1/?t=1370531712581 200 OK
535ms
socket.io.js (line 1659)
ParamsHeadersResponse
fPtjDNnugmPPXKbnN7ep:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
Can you please let me know why this is happening? is this kind of Firewall issue?
Thanks
After talking with you on the #nodejitsu IRC channel, it seems that this may indeed be a problem with your work proxy/firewall.
As was suggested to you in the chat last night, you could always try to use secure websocket connections (wss rather than ws) to see if that will allow your connections to pass through.
If that doesn't work, you would need to send your connection outside of your work's connection. For instance, proxying into a computer at your home and using your home network while you're at work and want to use websockets.

socket.io websocket connection invalid (latest chrome)

After installing node.js, I followed this tutorial to start a simple chat server. It was very easy to setup and is working, but I have noticed two problems:
1.) I am getting this warning from socket.io
info - socket.io started
debug - served static /socket.io.js
debug - client authorized
info - handshake authorized 1385647068766475337
debug - setting request GET /socket.io/1/websocket/1385647068766475337
debug - set heartbeat interval for client 1385647068766475337
warn - websocket connection invalid
This doesn't make sense to me because I didn't touch anything with socket.io and I am using the latest chrome version (23) which I know supports websockets (I am able to successfully connect to them with PHP-Websockets). It continues to use XHR instead, but I am really interested in getting the Websocket functionality working.
2.) When I go to localhost:8080 to connect to the chat server, it takes around 7-8 seconds for it to prompt me for my name and actually connect me to the server. I have a feeling this may be because it is reverting to XHR, but I don't really know much about it so I can't say. Any thoughts?
I saw this behaviour when using an older version of socket.io with later chrome builds (and other browsers also). It would timeout then fallback to xhr polling. To check your version of the socket.io library you are using, at your shell (linux/unix) type:
npm ls| grep socket.io
And it should tell you the version. The latest at this time is 0.9.13, which works.
If you are running the tutorial from http://psitsmike.com note that the package.json file hardcodes an older version of socket.io which doesn't work with the latest browsers.
Hope this helps.
I too was facing similar issues.
Your case -
Try deleting your cookies, sometimes the xhr-polling option once connected successfully is saved to cookies and reused every next time. Similar question answered here
Also debug - served static /socket.io.js sometimes come when the socket.io file is referred incorrectly inside the html or jade template file. Try correcting the script src link in case it wrong. It should be something like - var socket = io.connect('http://localhost:3000'); OR you can also try removing the link all together like this - var socket = io.connect();
Hope it helps.
I had the exact same issue. this might be old. but My setup is on digitalocean. what happens is that usually people who run node apps on one server use nginx for the port listen and node under its own dedicated port. nginx did not forward the websocket port to the node, only port 80 which nodejs was not initialised to begin with.
http://nginx.org/en/docs/http/websocket.html
You need to make sure your nginx is configured properly for this.
I just added the port to the io.connect directly connecting to the node server and avoiding nginx.

XMPPHP Could not connect after timeout

I am trying to create a web based PHP application which can allow chat to my Gmail friends. Something like meebo.com. I downloaded XMPPHP, and executed on localhost, and it is working fine, but when I uploaded everything to Yahoo Small business web hosting, it is throwing connection timeout error.
Do anyone else faced such problem. I heard many of them did, but no one have any solution yet.
Any suggestion will be very helpful. I am new to XMPP clients.
Just some ideas...
How are you trying to connect to the XMPP server? With XMPPHP you may use two classes which are
XMPPHP
XMPPHP_BOSH
You might try both, since they work on different ports (XMPPHP for example on 5222 and XMPPHP_BOSH on 80). So if this is a port issue, trying XMPPHP_BOSH would be an idea. You will need to find out though if this is supported by the XMPP server you are trying to connect to. And if so, you need to know the url the server exposes the BOSH service on.
Anyways, I would recommend to check out what kind of 'restrictions' there are in Yahoo Small business web hosting and on the side of the XMPP server.
If you intend to check XMPPHP_BOSH out, consider this issue to make it work: Issue 47: Http-bind error. All in all XMPPHP seems very buggy and incomplete...

Resources