Randomly getting the RangeError: Maximum call stack size exceeded when send the data to connected client(s) via Socket.IO room concept. Gone through few forums it is stating that the data object may have self-referencing array Node.js + Socket.io Maximum call stack size exceeded this exception may occurs but in my code I getting the exception in both the plain string data & data object also.
Below are the sample code snips
Sending plain text
socket.emit('STATUS','OK');
Stack Trace
Error in SendPlainText : RangeError: Maximum call stack size exceeded
at TLSSocket.Socket._writeGeneric (net.js:1:1)
at TLSSocket.Socket._write (net.js:783:8)
at doWrite (_stream_writable.js:397:12)
at writeOrBuffer (_stream_writable.js:383:5)
at TLSSocket.Writable.write (_stream_writable.js:290:11)
at TLSSocket.Socket.write (net.js:707:40)
at Sender.sendFrame (/node_v0_10_36/node_modules/ws/lib/Sender.js:390:20)
at Sender.send (/node_v0_10_36/node_modules/ws/lib/Sender.js:312:12)
at WebSocket.send (/node_v0_10_36/node_modules/ws/lib/WebSocket.js:377:18)
at send (/node_v0_10_36/node_modules/engine.io/lib/transports/websocket.js:114:17)
Sending object data
var clients = socketio.sockets.adapter.rooms['ROOMID'];
if(clients != undefined && clients != null)
{
console.log('Sending data to client');
socketio.sockets.in('ROOMID').emit('DATA', data);
}
Stack Trace
Error in SendData : RangeError: Maximum call stack size exceeded
at /node_v0_10_36/node_modules/engine.io-parser/lib/index.js:236:12
at proxy (/node_v0_10_36/node_modules/after/index.js:23:13)
at /node_v0_10_36/node_modules/engine.io-parser/lib/index.js:255:7
at /node_v0_10_36/node_modules/engine.io-parser/lib/index.js:231:7
at Object.exports.encodePacket (/node_v0_10_36/node_modules/engine.io-parser/lib/index.js:79:10)
at encodeOne (/node_v0_10_36/node_modules/engine.io-parser/lib/index.js:230:13)
at map (/node_v0_10_36/node_modules/engine.io-parser/lib/index.js:253:5)
at Object.exports.encodePayload (/node_v0_10_36/node_modules/engine.io-parser/lib/index.js:235:3)
at XHR.Polling.send (/node_v0_10_36/node_modules/engine.io/lib/transports/polling.js:246:10)
at Socket.flush (/node_v0_10_36/node_modules/engine.io/lib/socket.js:431:20)