Delayed socket.io response, and "warn - websocket connection invalid" - node.js

I am running a nodeJS + Express + socket.io + httpd application on an AWS EC2 instance.
Upon loading the page, the logger provides this information:
GET / 200 2ms - 1.23kb
GET /javascripts/script.js 304 1ms
debug - served static content /socket.io.js
GET /stylesheets/style.css 304 1ms
GET /stylesheets/style.css 304 1ms
GET /images/052.png 304 1ms
GET /Candara.ttf 304 1ms
debug - client authorized
info - handshake authorized EgWLPeyO2uiCTSui01CP
debug - setting request GET /socket.io/1/websocket/EgWLPeyO2uiCTSui01CP
debug - set heartbeat interval for client EgWLPeyO2uiCTSui01CP
warn - websocket connection invalid
info - transport end (undefined)
debug - set close timeout for client EgWLPeyO2uiCTSui01CP
debug - cleared close timeout for client EgWLPeyO2uiCTSui01CP
debug - cleared heartbeat interval for client EgWLPeyO2uiCTSui01CP
At this point, things will halt for about 5 seconds, after which:
debug - setting request GET /socket.io/1/xhr-polling/EgWLPeyO2uiCTSui01CP?t=1376937523124
debug - setting poll timeout
debug - client authorized for
debug - clearing poll timeout
debug - xhr-polling writing 1::
debug - set close timeout for client EgWLPeyO2uiCTSui01CP
debug - setting request GET /socket.io/1/xhr-polling/EgWLPeyO2uiCTSui01CP?t=1376937523490
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client EgWLPeyO2uiCTSui01CP
After this point, things start working well as far as I can tell, and events are fired and received without delays (if an event is fired before the 5 seconds delay described above, they will not be processed until after the delay has completed). The problem is how to remove that 5 seconds delay.
The client-side JS looks like this:
window.onload = function () {
var socket = io.connect("http://xxx.us-west-2.compute.amazonaws.com", {resource: "/socket.io"});
The server-side JS looks like this:
var express = require('express');
var app = express();
var io = require("socket.io").listen(app.listen(3000));
My httpd.conf file looks like this:
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
allow from all
</Location>
How can I avoid the initial delay and establish a healthy connection to socket.io?

I fixed the problem by restricting the allowed transport methods to "xhr-polling" and "jsonp-polling". I believe this is because Apache/2.2.25 doesn't offer support for the others.
The relevant code was added server-side:
io.set("transports", ["xhr-polling", "jsonp-polling"]);

Related

Nodejs to Couchbase Server timed out

My app is actually running fine when I started it and keep an eye on it for few hours.
BUT later time(I'm not sure what exact time of inactivity), It does show "Server timed out" (I crop some logs below)
[ERROR] (server - L:463) <node.mycouchbase.server:11210> (SRV=0x2111c60,IX=4) Server timed out. Some commands have failed
[INFO] (confmon - L:166) Not applying configuration received via CCCP. No changes detected. A.rev=152466, B.rev=152466
[INFO] (cccp - L:110) Re-Issuing CCCP Command on server struct 0x2116980
[ERROR] (cccp - L:133) <NOHOST:NOPORT> Got I/O Error=0x17
[INFO] (cccp - L:110) Re-Issuing CCCP Command on server struct 0x2185e30
All just working fine again when I restart my Node.js app (Expressjs app).
This problem seem regularly happening
Please give me some suggestion what could be actually problems behind.
Thanks

canvasengine Tiled_server Error: ENOENT, open './map.json'

This is my problem:
I try start Canvasengine example server and I get this error.
root#vps185158:/# node /var/www/canvas/canvasengine/examples/tiled_server/server/server.js
info - socket.io started
debug - client authorized
info - handshake authorized ogjRNMePBqcD_ZIkFVFK
debug - setting request GET /socket.io/1/websocket/ogjRNMePBqcD_ZIkFVFK
debug - set heartbeat interval for client ogjRNMePBqcD_ZIkFVFK
debug - client authorized for
debug - websocket writing 1::
/node_modules/canvasengine/core/engine-common.js:373
if (err) throw err;
^
Error: ENOENT, open './map.json'
at Error (native)
map.json is there, but nodejs can't find that file.
Server have Debian 7, nodejs, Socket.io and CanvasEngine 1.3.0
Looking at the code, you should either copy map.json to your working directory (which seems to be /, so I wouldn't necessarily recommend that) or start the server from its respective directory:
$ cd /var/www/canvas/canvasengine/examples/tiled_server/server/
$ node server
(although this may require setting $NODE_PATH)

Nginx SSL Handshake Error

I am getting following error in my server log :
[crit] 915#0: *46701 SSL_do_handshake() failed (SSL:
error:140A1175:SSL routines:SSL_BYTES_TO_CIPHER_LIST:inappropriate
fallback) while SSL handshaking, client: 187.50.199.66, server:
0.0.0.0:443
What does it mean ? How can I solve it ?
Please help me.
It looks, as it's connected with security bug in OpenSSL. It's nothing to do with YOUR nginx configuration. It's just indicating that your server has client which inproperly handles SSL handshakes.
What is SSL handshake?
Basically it's exchanging some messages between client and server at the beggining of each session. It consists of 6 phases:
Client Hello
Server Hello
Authentication and Pre-Master Secret
Decryption and Master Secret
Generate Session Keys
Encryption with Session Key
Read more at http://www.symantec.com/connect/blogs/how-does-ssl-work-what-ssl-handshake
To sum up - your server is raising this warning to indicate that some client is (un)intentionally breaking this procedure (for example, prematurely ending connection, or trying to open it several times in one session.
How to solve it?
If you really want to get rid of this message (it's not recommended) you can change level of error logging 9in your nginx.conf file), to something like:
error_log logs/error.log alert;
*available levels are: debug | info | notice | warn | error | crit | alert | emerg
http://nginx.org/en/docs/ngx_core_module.html#error_log

Socket.IO and Node.js Core Cluster

Is it possible to use Socket.IO with Node's core cluster (not the outdated module)?
I can fork multiple workers and it seems to work fine; however, when opening a connection I get the error: solve: warn - client not handshaken client should reconnect
Here's the relevant code snippet (with a few simple things like expressjs config removed):
if ( cluster.isMaster ) {
for ( var i = 0; i < numCPUs; i++ ) {
cluster.fork();
}
} else {
app.get('/', function (req, res) {
res.sendfile( __dirname + '/public/html/index.html' );
});
io.configure( function() {
var RedisStore = require('socket.io').RedisStore,
opts = { host: 'localhost', port: 8888 };
io.set('store', new RedisStore( { redisPub: opts, redisSub: opts, redisClient: opts } ));
});
app.listen( 8888 );
io.sockets.on('connection', function (socket) {
socket.emit( 'some', 'data' );
});
}
I've tried with and without using RedisStore and with the trick on this site (which I believe is obsolete now): http://www.danielbaulig.de/socket-ioexpress/
I've also looked at the code at http://www.ranu.com.ar/2011/11/redisstore-and-rooms-with-socketio.html, although I don't see how that code is any different than using MemoryStore.
All of my test connections are using Websockets (RFC 6455). This works fine if I set numCPUs to equal 1.
Node.js version 0.6.17
Socket.io version 0.9.5
Expressjs version 2.5.9
Update - include console output (note, on this attempt the connection did ultimately work, although it threw the same errors):
info - socket.io started
info - socket.io started
info - socket.io started
info - socket.io started
info - socket.io started
debug - served static content /socket.io.js
debug - client authorized
info - handshake authorized 17644195072103946664
debug - setting request GET /socket.io/1/websocket/17644195072103946664
debug - set heartbeat interval for client 17644195072103946664
debug - websocket writing 7:::1+0
warn - client not handshaken client should reconnect
info - transport end (error)
debug - set close timeout for client 17644195072103946664
debug - cleared close timeout for client 17644195072103946664
debug - cleared heartbeat interval for client 17644195072103946664
debug - discarding transport
debug - client authorized
info - handshake authorized 16098526291524652257
debug - setting request GET /socket.io/1/websocket/16098526291524652257
debug - set heartbeat interval for client 16098526291524652257
debug - websocket writing 7:::1+0
warn - client not handshaken client should reconnect
info - transport end (error)
debug - set close timeout for client 16098526291524652257
debug - cleared close timeout for client 16098526291524652257
debug - cleared heartbeat interval for client 16098526291524652257
debug - discarding transport
debug - client authorized
info - handshake authorized 13419993801561067603
debug - setting request GET /socket.io/1/websocket/13419993801561067603
debug - set heartbeat interval for client 13419993801561067603
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"some":"data","args":[11354]}
debug - websocket writing 5:::{"some":"data","args":[36448]}
This is how the console output ends on a failure (fails about 9 times out of 10):
info - transport end by forced client disconnection
debug - websocket writing 0::
info - transport end (booted)
debug - set close timeout for client 1639301251431944437
debug - cleared close timeout for client 1639301251431944437
debug - cleared heartbeat interval for client 1639301251431944437
debug - discarding transport
debug - got disconnection packet
debug - got disconnection packet
Update - Added links to possible tickets on github:
https://github.com/LearnBoost/socket.io/issues/881
https://github.com/LearnBoost/socket.io/issues/438
It seems the issue may be related to the node module that Socket.IO comes installed with.
When I installed redis (npm install hiredis redis) and created the clients for the RedisStore using the redis module, everything suddenly worked perfectly. I've been running for over an hour with ~500 concurrent connections and haven't seen a single error, and every node process is being utilized.
hiredis#0.1.14
redis#0.7.2
Running Redis 2.6rc3 on port 6379.
Update: In Node.s 0.8, it looks like the cluster library should be considerably more mature, so the above code/issues will probably become obsolete: http://nodejs.org/docs/v0.7.8/api/cluster.html

Node.js 0.4.10. http get( ) request " ETIMEDOUT Connection timed out " frequently

Recently, I sank into the issue on "ETIMEDOUT Connection timed out".
My application just use the get() method to download files and data from the remote server.
during the downloading(I mean I have downloaded some files but not completely), I just get the "ETIMEDOUT Connection timed out". It's a bug of node.js? I use node.js 0.4.10. Because of the ETIMEDOUT, I cannot download files completely.
http = require('http');
client_req = http.get(...)//
//...
client_req.on('error', callback(err){...})/*When ETIMEDOUT, I get the error
message: ETIMEDOUT Connection timed out here.*/
This is not a Node.js bug, most probably the url cannot be reached anymore, that's why you get a timeout. As #DeaDEnD suggested, do a curl to see if you get a timeout also with cURL.

Resources