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

unable to use 'bindings' module after lockdown (used by node-lmdb) #308

Closed
warner opened this issue May 15, 2020 · 2 comments
Closed

unable to use 'bindings' module after lockdown (used by node-lmdb) #308

warner opened this issue May 15, 2020 · 2 comments

Comments

@warner
Copy link
Contributor

warner commented May 15, 2020

When install-ses.js is a file that imports SES-0.7.7 and calls lockdown(), the following program:

import './install-ses.js';
import lmdb from 'node-lmdb';

fails like:

$ node -r esm t.js
/home/warner/stuff/agoric/agoric-sdk/node_modules/bindings/bindings.js:1
TypeError: Cannot read property 'indexOf' of undefined
    at Function.getFileName (/home/warner/stuff/agoric/agoric-sdk/node_modules/bindings/bindings.js:178:16)
    at bindings (/home/warner/stuff/agoric/agoric-sdk/node_modules/bindings/bindings.js:82:48)
    at Object.<anonymous> (/home/warner/stuff/agoric/agoric-sdk/node_modules/node-lmdb/index.js:3:37)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/home/warner/stuff/agoric/agoric-sdk/packages/swing-store-lmdb/t.js:1)
    at Generator.next (<anonymous>)

The core problem seems to be the bindings module used by node-lmdb, which modifies Error to learn the filename of the invoking module (and leverage that to find the DLL/.so that needs to be imported):

exports.getFileName = function getFileName(calling_file) {
  var origPST = Error.prepareStackTrace,
    origSTL = Error.stackTraceLimit,
    dummy = {},
    fileName;

  Error.stackTraceLimit = 10;

  Error.prepareStackTrace = function(e, st) {
    for (var i = 0, l = st.length; i < l; i++) {
      fileName = st[i].getFileName();
      if (fileName !== __filename) {
        if (calling_file) {
          if (fileName !== calling_file) {
            return;
          }
        } else {
          return;
        }
      }
    }
  };

  // run the 'prepareStackTrace' function above
  Error.captureStackTrace(dummy);
  dummy.stack;

  // cleanup
  Error.prepareStackTrace = origPST;
  Error.stackTraceLimit = origSTL;

  // handle filename that starts with "file://"
  var fileSchema = 'file://';
  if (fileName.indexOf(fileSchema) === 0) {
    fileName = fileURLToPath(fileName);
  }

  return fileName;
};

The error is due to fileName being undefined, probably because prepareStackTrace was not successfully overridden. Calling lockdown() with noTameError: true doesn't help.

@warner
Copy link
Contributor Author

warner commented May 15, 2020

For LMDB, one workaround is to import 'node-lmdb' (for side-effects only, no imported names) before install-ses, then let the normal code import it again afterwards. It looks like the DLL is located (and maybe loaded) the first time it gets imported. This still falls into the "vetted shim" category, but it's at least a functional workaround.

warner added a commit to Agoric/agoric-sdk that referenced this issue May 28, 2020
include a workaround for endojs/endo#308 which
would break the LMDB module
@warner
Copy link
Contributor Author

warner commented May 29, 2020

This is an instance of #251, closing in favor of the other ticket.

@warner warner closed this as completed May 29, 2020
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

1 participant