Node.js + Socket.io Maximum call stack size exceeded

The answer is very helpful. Thanks.

I just had the same issue and want to share with anyone who might encounter it.

My code uses express.js and has the following:

io = require('socket.io').listen(server);
......
io.to(socketId).emit('hello', {userId:userId, data:data, res:res});

It generated the "Maximum call stack exceeded" error. The problem is that I should not send the variable 'res' over the socketio to the client. I guess it will cause some recursive behavior if I do so.

The solution is just remove the 'res' from the emit statement:

io.to(socketId).emit('hello', {userId:userId, data:data});

Found my issue.

The object (temp) I was trying to send over the network (in socket.emit('roll_result',temp);) was a self-referencing array. It was the recursive property of the array that caused the stack to exceed the max size.