-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RangeError: Maximum call stack size exceeded #1665
Comments
Found a "solution" to my problem. I can send every single piece of data sperated, but it DOES NOT work with objects |
I have recently been getting that error also, the only difference being that it only occasionally happens for me. Been testing all morning and I have not been able to replicate the problem. |
For me it was that it only wasn´t able to emit to everbody, when the obj was to big. |
@BenBals if the object is too big, then a decent workaround is to send it in form of a string i.e. run |
I got another work around, but I considered that. |
😢 looking into this |
has the same problem when emitting a object of type: had to add the field content directly to the objects because hasBin() only checks the first level of a object. But when it then tried to send the buffer it got 'Maximum call stack exceeded' |
You can replicate this by emitting the socket object (one way at least) so (Below would be server to -> client )
I'm curious if this has an actual fix though. |
Any update on that issue ? |
Interestingly enough, I'm getting this same error when attempting to pass my Firebase data to the client side. Error node_modules/socket.io/node_modules/has-binary-data/index.js:46
for (var key in obj) {
^
RangeError: Maximum call stack size exceeded Server-side var DB = new Firebase('https://1234abcd.firebaseIO.com');
var USERS = DB.child("users");
io.sockets.on('connection', function(socket){
socket.emit('test', {
db: USERS
});
}); |
해결책을 찾습니다... |
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. |
One thing var props = [];
var obj = { a: 1, b:2, c: { d: 3, e: 4 } };
function next_prop(callback){
if (!props.length){
setTimeout(callback);
return;
}
var prop = props.shift();
//do whatever with the prop, call parse_obj on it if it's an object
setTimeout(next_prop);
}
function parse_obj(obj, callback){
for (var i in obj){
props.push(i);
}
setTimeout(function(){next_prop(callback);});
}
parse_obj(obj); Of course, this isn't actual code you should use, because there needs to be wrapping of functions for each individual object in case they're nested, otherwise you'll have conflicts with what object is being parsed. |
I just get that error too, my code is like: "io.sockets.emit('key', data);" when your "data" object has recursive attribute refering, this code would crash. |
+1 would the core team like a async version of of binary checking i can help get that setup |
I can reproduce the problem by sending the socket object :) |
+1 IE11 shows 'out of stack space' in _hasBinary. |
This error showed for me when I was trying to send the whole socket object back to the client. All I really needed was |
This probably happened because you were trying to send an object with circular references resulting in recursive calls that exceeded the stack size. |
@LordMajestros That fixed it for me! Thanks |
@GerbenHofman you're welcome |
I faced same error on NodeJS v4.4.4 and socket.io v1.4.5. In my case, it happens after disconnect event. If the number of call The parameter I use with Does this information helps you? |
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. |
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. |
There are quite a few decent solutions for detecting circular data: https://stackoverflow.com/questions/14962018/detecting-and-fixing-circular-references-in-javascript One short solution relies on JSON.stringify to find the problem:
More details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value |
@adamreisnz You are welcome to make a PR ;) |
It always catches me off guard when someone mentions me 5 months after I made a comment 😆 |
I met this error too. And that's why I waste two hours to check my whole codes :<. |
I just ran into this as well.
|
Shucks, I see there is a PR that has been open for 2 years that would fix this: |
@dustingraham the fix does look great, though I'm not sure about the performance implications. Also, even if it doesn't throw in the > var a = {};
undefined
> var b = { a: a };
undefined
> a.b = b
{ a: { b: [Circular] } }
> JSON.stringify(a)
Thrown:
TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>) |
For future readers: sending packet with circular references is not supported by default, since the default parser relies on If you have such a use case, you can provide your own parser: https://socket.io/docs/v3/custom-parser/ |
Anyone got any solution. |
He is Korean |
Check if there is a circle json object, because when you emit an event with data which is an object, it will convert the object to string by recursion. If you transfer a circle object, it will cause endless recursion. |
I am just calling `ìo.sockets.emit('hey', data);
and it will crash with
RangeError: 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 in``socket.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:My code is:
The text was updated successfully, but these errors were encountered: