Skip to content
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

Maximum call stack size exceeded #484

Open
jiutianxuannan opened this issue Jun 15, 2021 · 4 comments
Open

Maximum call stack size exceeded #484

jiutianxuannan opened this issue Jun 15, 2021 · 4 comments

Comments

@jiutianxuannan
Copy link

jiutianxuannan commented Jun 15, 2021

new sharedb.Connection(this.socket)

@alecgibson
Copy link
Collaborator

Going to need a bit more information than this, please.

@maxfortun
Copy link

I am not sure if this is the same issue that the original author is facing, but I just hit the same error message.
I am not sure how to replicate this, but here are some observations.

Stack trace:

RangeError: Maximum call stack size exceeded
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:196:22)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3
    at next (/root/apps/djsp-cfg-pubedit-sh-svc-sharedb/node_modules/sharedb/lib/backend.js:200:5)
    at /root/apps/djsp-cfg-pubedit-sh-svc-sharedb/bin/www:122:3

The code at www:122 is calling next().

backend.use('submit', (context, next) => {
  Object.assign(context.op.m, context.agent.custom);
  context.opMetadataProjection = { username: true };
  next();
 });

The code at backend.js:200 is calling fn(request, next):

sharedb/lib/backend.js

Lines 186 to 203 in 3e636d0

Backend.prototype.trigger = function(action, agent, request, callback) {
request.action = action;
request.agent = agent;
request.backend = this;
var fns = this.middleware[action];
if (!fns) return callback();
// Copying the triggers we'll fire so they don't get edited while we iterate.
fns = fns.slice();
var next = function(err) {
if (err) return callback(err);
var fn = fns.shift();
if (!fn) return callback();
fn(request, next);
};
next();
};

From what I can tell, the next, since it is defined in the outer block with var, is global scoped, and thus when it is passed into fn() has the prior state. That aside, I do not fully understand what this code is trying to achieve. It is defining next as a function, and then calling the next it is defining from its own definition. It doesn't look to be intentional.

@maxfortun
Copy link

Looks like instead of passing next, the code should be passing callback. Adding fix to [#513].

fn(request, callback);

@alecgibson
Copy link
Collaborator

I left a comment on #513 but reiterating here: I think we should open a separate PR for this change to discuss. As a heads-up, I won't have time until next week to look at it properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants