socket.io: RangeError: Maximum call stack size exceeded

I am just calling `ìo.sockets.emit(‘hey’, data);and it will crash withRangeError: Maximum call stack size exceeded. I use it in other places in my app and it works fine. I am not repeating this (checked with console). The logs say the error is insocket.io/node_modules/has-binary-data/index.js:46``.

I dont know where the problem is. I tried logging io.sockets right before using it and it outputs this:


{ name: '/',
17:39:37 web.1  |   server:
17:39:37 web.1  |    { nsps: { '/': [Circular] },
17:39:37 web.1  |      _path: '/socket.io',
17:39:37 web.1  |      _serveClient: true,
17:39:37 web.1  |      _adapter: [Function: Adapter],
17:39:37 web.1  |      _origins: '*:*',
17:39:37 web.1  |      sockets: [Circular],
17:39:37 web.1  |      eio:
17:39:37 web.1  |       { clients: [Object],
17:39:37 web.1  |         clientsCount: 2,
17:39:37 web.1  |         pingTimeout: 60000,
17:39:37 web.1  |         pingInterval: 25000,
17:39:37 web.1  |         upgradeTimeout: 10000,
17:39:37 web.1  |         maxHttpBufferSize: 100000000,
17:39:37 web.1  |         transports: [Object],
17:39:37 web.1  |         allowUpgrades: true,
17:39:37 web.1  |         allowRequest: [Function],
17:39:37 web.1  |         cookie: 'io',
17:39:37 web.1  |         ws: [Object],
17:39:37 web.1  |         _events: [Object] },
17:39:37 web.1  |      engine:
17:39:37 web.1  |       { clients: [Object],
17:39:37 web.1  |         clientsCount: 2,
17:39:37 web.1  |         pingTimeout: 60000,
17:39:37 web.1  |         pingInterval: 25000,
17:39:37 web.1  |         upgradeTimeout: 10000,
17:39:37 web.1  |         maxHttpBufferSize: 100000000,
17:39:37 web.1  |         transports: [Object],
17:39:37 web.1  |         allowUpgrades: true,
17:39:37 web.1  |         allowRequest: [Function],
17:39:37 web.1  |         cookie: 'io',
17:39:37 web.1  |         ws: [Object],
17:39:37 web.1  |         _events: [Object] } },
17:39:37 web.1  |   sockets:
17:39:37 web.1  |    [ { nsp: [Circular],
17:39:37 web.1  |        server: [Object],
17:39:37 web.1  |        adapter: [Object],
17:39:37 web.1  |        id: 'RfgXeMgHeP_9SQC5AAAC',
17:39:37 web.1  |        client: [Object],
17:39:37 web.1  |        conn: [Object],
17:39:37 web.1  |        rooms: [Object],
17:39:37 web.1  |        acks: {},
17:39:37 web.1  |        connected: true,
17:39:37 web.1  |        disconnected: false,
17:39:37 web.1  |        handshake: [Object],
17:39:37 web.1  |        _events: [Object] },
17:39:37 web.1  |      { nsp: [Circular],
17:39:37 web.1  |        server: [Object],
17:39:37 web.1  |        adapter: [Object],
17:39:37 web.1  |        id: '7TEjGJjWzxObulClAAAD',
17:39:37 web.1  |        client: [Object],
17:39:37 web.1  |        conn: [Object],
17:39:37 web.1  |        rooms: [Object],
17:39:37 web.1  |        acks: {},
17:39:37 web.1  |        connected: true,
17:39:37 web.1  |        disconnected: false,
17:39:37 web.1  |        handshake: [Object],
17:39:37 web.1  |        _events: [Object] } ],
17:39:37 web.1  |   connected:
17:39:37 web.1  |    { RfgXeMgHeP_9SQC5AAAC:
17:39:37 web.1  |       { nsp: [Circular],
17:39:37 web.1  |         server: [Object],
17:39:37 web.1  |         adapter: [Object],
17:39:37 web.1  |         id: 'RfgXeMgHeP_9SQC5AAAC',
17:39:37 web.1  |         client: [Object],
17:39:37 web.1  |         conn: [Object],
17:39:37 web.1  |         rooms: [Object],
17:39:37 web.1  |         acks: {},
17:39:37 web.1  |         connected: true,
17:39:37 web.1  |         disconnected: false,
17:39:37 web.1  |         handshake: [Object],
17:39:37 web.1  |         _events: [Object] },
17:39:37 web.1  |      '7TEjGJjWzxObulClAAAD':
17:39:37 web.1  |       { nsp: [Circular],
17:39:37 web.1  |         server: [Object],
17:39:37 web.1  |         adapter: [Object],
17:39:37 web.1  |         id: '7TEjGJjWzxObulClAAAD',
17:39:37 web.1  |         client: [Object],
17:39:37 web.1  |         conn: [Object],
17:39:37 web.1  |         rooms: [Object],
17:39:37 web.1  |         acks: {},
17:39:37 web.1  |         connected: true,
17:39:37 web.1  |         disconnected: false,
17:39:37 web.1  |         handshake: [Object],
17:39:37 web.1  |         _events: [Object] } },
17:39:37 web.1  |   fns: [],
17:39:37 web.1  |   ids: 0,
17:39:37 web.1  |   acks: {},
17:39:37 web.1  |   adapter:
17:39:37 web.1  |    { nsp: [Circular],
17:39:37 web.1  |      rooms:
17:39:37 web.1  |       { '5MGPNOdO4th_dOuZAAAA': [],
17:39:37 web.1  |         '64rUhxxp--4Qk1MqAAAB': [],
17:39:37 web.1  |         RfgXeMgHeP_9SQC5AAAC: [Object],
17:39:37 web.1  |         '7TEjGJjWzxObulClAAAD': [Object] },
17:39:37 web.1  |      sids:
17:39:37 web.1  |       { RfgXeMgHeP_9SQC5AAAC: [Object],
17:39:37 web.1  |         '7TEjGJjWzxObulClAAAD': [Object] },
17:39:37 web.1  |      encoder: {} },
17:39:37 web.1  |   _events: { connection: [Function] } }

My code is:


if (game.scoreTeamTwo > game.scoreTeamOne && game.scoreTeamTwo > game.scoreTeamThree && game.scoreTeamTwo > game.scoreTeamFour) {
              game.winner = 2;
              io.sockets.emit('CTFEnd', game);
}

//It´s just looking if team 1 won the game and when it does is emits ````CTFEnd```` and all the other game data

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 6
  • Comments: 37 (3 by maintainers)

Most upvoted comments

This probably happened because you were trying to send an object with circular references resulting in recursive calls that exceeded the stack size.

해결책을 찾습니다…

Sorry, but my Chinese isn’t that great. Would you be so kind to translate this into English.

Did a Google Translate & it comes out to “Find the Solution…” … hardly worth responding to. For record, the solution is to not pass such large amount of data via socket.io … it’s a socket which was designed for quick, short responses. Break up your response or send it via ajax. Unsubscribing to this thread.

For me it was that it only wasn´t able to emit to everbody, when the obj was to big.

Is there any chance of Socket IO implementing a guard against recursive data being emitted from and failing with this error? A simple detection could prevent this error from happening and emit instead a more meaningful error, like “You may be trying to send circular data”. That would make it easier to debug.

I can reproduce the problem by sending the socket object 😃

Any update on that issue ? EDIT: My issue was that I was trying to send recursive objects.

You can replicate this by emitting the socket object (one way at least) so (Below would be server to -> client )

socket.emit('crash', {socket:socket});

I’m curious if this has an actual fix though.

Found a “solution” to my problem. I can send every single piece of data sperated, but it DOES NOT work with objects

Just to add to @shunjikonishi , I’ve seen this happen as soon as I have sent exactly 100,000 events via io.emit. I have 1 socked connected, so seems like 100,000 is a hard cap.

Seems like this is a limit imposed by Node (or the JavaScript runtime) and Socket.io is holding a reference to something every time you call emit, so when you hit the 100,000th emit it just falls over.

Tested with Node 5.11.0 and Socketio 1.4.8. My version of Node is different (as well as my operating system etc, really no idea where this 100,000 comes from) than @shunjikonishi which may explain why I hit the limit at 100,000 whereas he got up to 200,000.

I ran the exact same code using ws.js and it worked fine, surpassed 100,000 socket emits without problem, so maybe it’s a problem with Socket.io.