konecty/meteor-user-presence

Error on process.exit(0). Meteor code must always run within a Fiber.

allenlau opened this issue · 0 comments

Trying to run some CI jobs using dispatch:mocha-phantomjs with Meteor 1.3. When dispatch:mocha-phantomjs tries to exit with process.exit(0), this error always occurs:

W20160602-18:45:01.931(-7)? (STDERR)
W20160602-18:45:01.931(-7)? (STDERR) /tmp/meteor-test-run1iqje6z/.meteor/local/build/programs/server/packages/meteor.js:1060
W20160602-18:45:01.931(-7)? (STDERR) throw new Error("Meteor code must always run within a Fiber. " +
W20160602-18:45:01.931(-7)? (STDERR) ^
W20160602-18:45:01.935(-7)? (STDERR) Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
W20160602-18:45:01.935(-7)? (STDERR) at Object.Meteor.nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9:1)
W20160602-18:45:01.936(-7)? (STDERR) at [object Object].
.extend.get (packages/meteor/dynamics_nodejs.js:21:1)
W20160602-18:45:01.936(-7)? (STDERR) at Object.Meteor.isRestricted (packages/dispatch_run-as-user/packages/dispatch_run-as-user.js:137:1)
W20160602-18:45:01.936(-7)? (STDERR) at [object Object].Mongo.Collection.(anonymous function) as update
W20160602-18:45:01.936(-7)? (STDERR) at Object.UserPresence.removeConnectionsByInstanceId (packages/konecty_user-presence/server/server.js:62:1)
W20160602-18:45:01.936(-7)? (STDERR) at process. (packages/konecty_user-presence/server/server.js:201:1)
W20160602-18:45:01.937(-7)? (STDERR) at process.emit (events.js:117:20)
W20160602-18:45:01.937(-7)? (STDERR) at process.exit (node.js:750:17)
W20160602-18:45:01.937(-7)? (STDERR) at exitIfDone (packages/dispatch:mocha-phantomjs/server.js:58:17)
W20160602-18:45:01.937(-7)? (STDERR) at ChildProcess.done (packages/dispatch:mocha-phantomjs/server.js:91:7)

Looks like it can be solved by add Meteor.bindEnvironment as suggested to the process.on('exit') handler in server/server.js. Here is the diff from my local package:
diff --git a/server/server.js b/server/server.js
index f2ab324..95a903c 100644
--- a/server/server.js
+++ b/server/server.js
@@ -196,13 +196,13 @@ UserPresence = {
});
});

  •           process.on('exit', function() {
    
  •           process.on('exit', Meteor.bindEnvironment(function() {
                    if (Package['konecty:multiple-instances-status']) {
                            UserPresence.removeConnectionsByInstanceId(InstanceStatus.id());
                    } else {
                            UserPresence.removeAllConnections();
                    }
    
  •           });
    
  •           }));
    
            if (Package['accounts-base']) {
                    Accounts.onLogin(function(login) {