felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

strange sandbox behavior with mongoose #9

Closed ericchaves closed 11 years ago

ericchaves commented 12 years ago

Hi Felix,

I'm facing a very odd behavior that I can't track down due to my beginner level on node.js. I use mocha to test my code and your's sandboxed-module (https://github.com/felixge/node-sandboxed-module) for dependency injection in some required modules for the code I'm testing.

Whenever I load a module that uses mongoose inside a sandbox all mongoose calls like model.save or model.find times-out unless I load the module twice. For example, in a piece of code like this (chopped for clarity):

    var User = sandbox.require('../../models/users', {
        requires: { // define some mocks... }
    });

    User = require('../../models/users');   

    var user = new User(user_data);
        user.save(function(err, doc){
            //do something on callback
    });

Without the User = require('../../models/users') the user.save call goes away and never callbacks. Including it makes everything works and the model class stils have the mocks injected just as if it was loaded by the sandbox.require call.

Have you heard about this before? Am I doing something wrong here?

Thanks for any help.

domenic commented 11 years ago

If this is still a problem, let me know, and we'll be sure to look into it!

moizr commented 11 years ago

I'm facing a similar problem. When I use sandboxed module to require a module - mongoose seems to timeout. @ericchaves if you found a solution to the problem please let me know.

chrismeyersfsu commented 10 years ago

I too am having the timeout problem. In my case, calling find or findOne on a mongoose model, with sandbox in the mix, results in the callback not being called back.

Update: the query .exec() from mongooses' dependent library mquery (mongoose/node_modules/mquery) is not getting called.

ericchaves commented 10 years ago

Sorry guys, unfortunately in the end I ditching mongoose in favor of the native mongodb driver (for other reasons other than this issue).