Error handling best practices?

1,111 views
Skip to first unread message

Hugo

unread,
Feb 18, 2011, 12:56:39 AM2/18/11
to Socket.IO
So....this afternoon I leave my dev environment running with a single
websocket client hitting the server with a message every 10sec or so.
After a looooong coffee break I return to find out that
1. The server-side code handling the messages has been spitting out
errors for the last 2hrs
2. I am not sure why, but it seems that the error caused the websocket
to disconnect after ~25sec, which in turn caused my client to
automatically reconnect by creating a new client, i.e. new io.Socket()
3. The server ran out of file descriptors after the said ~2hrs

I am not sure if I am reading the behavior correctly, but it seems my
message-processing error caused the heartbeat to stop (which in turn
caused the socket disconnect), and more concerning to me, it seems
like the associated file descriptors weren't released after the error.

In a perfect world, I never have error when processing an incoming
message but that ain't gonna happen...any recommendations out there
for handling that type of situation / cleaning up resources after an
error?

Environment: node.js v2.5, Socket.IO v0.6.11

Thanks!

Guillermo Rauch

unread,
Feb 18, 2011, 1:01:00 AM2/18/11
to sock...@googlegroups.com
What kind of errors where you seeing?
--
Guillermo Rauch
http://devthought.com

Hugo

unread,
Feb 18, 2011, 2:24:53 PM2/18/11
to Socket.IO
Basically my code goes

return socket.on('connection', function(client) {
client.on('message', function(msg) {
connector = getConnector(msg.connectorId)
connector.setExtend(msg) <<<<< This trows an error after
getConnector returns undefined
}
}

(Not the actual code...I adjusted for readability, but the point is,
an error is thrown while processing an incoming message)

Here is the stack trace

TypeError: Cannot call method 'setExtend' of undefined
at DriverConnector.onPayload (/Users/hugo/Dev/dispatch/src/classes/
connector/DriverConnector.js:66:18)
at [object Object].<anonymous> (/Users/hugo/Dev/dispatch/src/
ioApp.js:28:28)
at [object Object].emit (events:27:15)
at [object Object]._onMessage (/Users/hugo/.node_libraries/.npm/
socket.io/0.6.11/package/lib/socket.io/client.js:58:10)
at Parser.<anonymous> (native)
at Parser.emit (events:27:15)
at Parser.parse (/Users/hugo/.node_libraries/.npm/socket.io/0.6.11/
package/lib/socket.io/transports/websocket.js:198:12)
at Parser.add (/Users/hugo/.node_libraries/.npm/socket.io/0.6.11/
package/lib/socket.io/transports/websocket.js:185:8)
at Stream.<anonymous> (/Users/hugo/.node_libraries/.npm/socket.io/
0.6.11/package/lib/socket.io/transports/websocket.js:119:17)
at Stream.emit (events:27:15)

Truong Nguyen

unread,
Feb 18, 2011, 1:22:08 AM2/18/11
to sock...@googlegroups.com
I'm having issue with disconnected client as well. Got an error thrown in the console at line 1748 in socket.io.js

client.broadcast doesnt seems to work...

my code using the example as follow:
var io = io.listen(server);
io.on('clientConnect', function(client){
client.send({buffer: buffer});
client.on('message', function(keyword){
var msg = { message: [client.sessionId, keyword]};
client.broadcast(msg);
Reply all
Reply to author
Forward
0 new messages