I am developing a web-app with node.js and I am using socket.io in it. I have the problem that sometimes socket.io seems not to be working. When I give a look at the browser console, I see an "allocation size overflow" error message, which points to this piece of code:
var msgLength = '';
for (var i = 1; ; i++) {
if (tailArray[i] == 255) break;
msgLength += tailArray[i]; // this is the line which causes the error
}
If anyone wants to see more code, I will say these are the lines 3725-3729 of socket.io.js (obviously, client side file) of node's socket.io module, version 1.0.2.
It seems the function above is generating a too-long string. However, I have been investigating about the max length of a string and I found this SO question, which clearly indicates there's no string length limit. After a deeper investigation, I have found and reproduced an example which causes an "allocation size overflow" error warning on the browser. Here's the code:
var a = 'a';
for (var i = 0; i < 100; i++) {
a += a;
}
This code obviously has to crash because the final size of "a" has to reach and exceed the petabyte limit. However, I have seen that at the moment of crashing, the value of "i" was 27, so the size of "a" was 128 MB. The data I am handling with socket.io doesn't reach that size by far, so I wonder: what can be causing this "allocation size overflow", and how can I solve this?
Thanks!