2 Replies - 498 Views - Last Post: 14 May 2019 - 09:31 PM

#1 ethanzz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-April 18

socket.io causing unexpected errors?

Posted 19 April 2018 - 04:41 PM

I am writing some code in nodejs, but every time I run it, I get the same error:

/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:1
(function (exports, require, module, __filename, __dirname) { /* global Blob File */
^
    
RangeError: Maximum call stack size exceeded
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:1:1)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)
    at hasBinary (/path/to/home/Downloads/Boxez/node_modules/has-binary2/index.js:56:59)



This error seems like it's being thrown from the [has-binary2](https://www.npmjs.com/package/has-binary2) module. On inspection, the has-binary2 module is a dependency of socket.io (which I am using in my app). I can't figure out what is causing the error, let alone figure out how to fix it. Does anyone know why this error is being thrown, and how I would go about fixing it?

Is This A Good Question/Topic? 0
  • +

Replies To: socket.io causing unexpected errors?

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2334
  • View blog
  • Posts: 7,111
  • Joined: 15-January 14

Re: socket.io causing unexpected errors?

Posted 19 April 2018 - 05:04 PM

It looks like there is infinite recursion, the function is calling itself at line 56 or 59 and it keeps doing that until it reaches the max stack size.
Was This Post Helpful? 0
  • +
  • -

#3 sagar.chavada   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 10-April 19

Re: socket.io causing unexpected errors?

Posted 14 May 2019 - 09:31 PM

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.

This is almost always because of a recursive function with a base case that isn't being met.

In order to fix it, ensure that your recursive function has a base case which is able to be met.

(function a(x) {
    // The following condition 
    // is the base case.
    if ( ! x) {
        return;
    }
    a(--x);
})(10);

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1