Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

start_server callback not being called #12

Closed
azhang opened this issue Jan 22, 2016 · 8 comments
Closed

start_server callback not being called #12

azhang opened this issue Jan 22, 2016 · 8 comments

Comments

@azhang
Copy link

azhang commented Jan 22, 2016

I'm using Mockgoose for some tests running on Circlei, and have been running into an issue where it hangs when starting up mongodb. I've traced it back to the mongod.start_server never running the callback.

    mongod_emitter = mongod.start_server({args: db_opts, auto_shutdown: true}, function(err) {
        console.log("NOT STUCK")
    });

It works fine on my local machine (mac), but I can't seem to get it working on any circleci instance. Any ideas?

@winfinit
Copy link
Contributor

@azhang i've reworked this all deal in a last few days, i would suggest to use latest release, that should be all fixed now.

@jadamgreen1010-zz
Copy link

@winfinit On a related note, the start_server callback arg is getting called even if it's undefined (callback is not a function errors abound). Could we look before leaping here so people don't have to pass dummy callbacks?

Mockgoose as an example: mccormicka/Mockgoose#204

I'd be happy to PR if you'd like.

@greggman
Copy link

I'm actually having the same issue using 5.0.3

$ mkdir test
$ cd test
$ npm install mongodb-prebuilt

> [email protected] postinstall /Users/gregg/temp/delme-mongodb-test/node_modules/spawn-sync
> node postinstall


> [email protected] postinstall /Users/gregg/temp/delme-mongodb-test/node_modules/mongodb-prebuilt
> node install.js

done
inside extract, run complete
Done installing MongoDB
/Users/gregg/temp/delme-mongodb-test
└─┬ [email protected] 
  ├─┬ [email protected] 
  │ └── [email protected] 
  ├─┬ [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ └─┬ [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   └── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ ├── [email protected] 
  │ │ │ │ └─┬ [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   ├── [email protected] 
  │ │ │ │   └── [email protected] 
  │ │ │ └── [email protected] 
  │ │ ├── [email protected] 
  │ │ └─┬ [email protected] 
  │ │   ├── [email protected] 
  │ │   ├── [email protected] 
  │ │   └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ ├── [email protected] 
  │ │ └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ ├── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ ├── [email protected] 
  │ │ │ │ ├── [email protected] 
  │ │ │ │ ├── [email protected] 
  │ │ │ │ └── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ └── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ ├── [email protected] 
  │ │ │ └── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ └── [email protected] 
  │ │ │ ├─┬ [email protected] 
  │ │ │ │ └─┬ [email protected] 
  │ │ │ │   └── [email protected] 
  │ │ │ └── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ └─┬ [email protected] 
  │ │ │   └── [email protected] 
  │ │ └─┬ [email protected] 
  │ │   └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ └─┬ [email protected] 
  │ │ │   └── [email protected] 
  │ │ └─┬ [email protected] 
  │ │   └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ └─┬ [email protected] 
  │ │   └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ ├── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ └─┬ [email protected] 
  │ │ │   └── [email protected] 
  │ │ ├── [email protected] 
  │ │ ├─┬ [email protected] 
  │ │ │ └── [email protected] 
  │ │ └─┬ [email protected] 
  │ │   └─┬ [email protected] 
  │ │     └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ └── [email protected] 
  │ ├─┬ [email protected] 
  │ │ └── [email protected] 
  │ └─┬ [email protected] 
  │   ├─┬ [email protected] 
  │   │ └── [email protected] 
  │   ├─┬ [email protected] 
  │   │ ├─┬ [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ └─┬ [email protected] 
  │   │ │ │   ├── [email protected] 
  │   │ │ │   └── [email protected] 
  │   │ │ └── [email protected] 
  │   │ ├─┬ [email protected] 
  │   │ │ └── [email protected] 
  │   │ ├─┬ [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ ├─┬ [email protected] 
  │   │ │ │ │ └─┬ [email protected] 
  │   │ │ │ │   ├── [email protected] 
  │   │ │ │ │   ├── [email protected] 
  │   │ │ │ │   ├── [email protected] 
  │   │ │ │ │   └── [email protected] 
  │   │ │ │ ├── [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ ├── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ ├─┬ [email protected] 
  │   │ │ │ │ └── [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ ├─┬ [email protected] 
  │   │ │ │ ├── [email protected] 
  │   │ │ │ └── [email protected] 
  │   │ │ └─┬ [email protected] 
  │   │ │   ├── [email protected] 
  │   │ │   └── [email protected] 
  │   │ ├─┬ [email protected] 
  │   │ │ └── [email protected] 
  │   │ ├─┬ [email protected] 
  │   │ │ └── [email protected] 
  │   │ └─┬ [email protected] 
  │   │   └─┬ [email protected] 
  │   │     └── [email protected] 
  │   ├── [email protected] 
  │   ├─┬ [email protected] 
  │   │ ├── [email protected] 
  │   │ └─┬ [email protected] 
  │   │   └── [email protected] 
  │   ├── [email protected] 
  │   ├── [email protected] 
  │   ├─┬ [email protected] 
  │   │ ├── [email protected] 
  │   │ ├── [email protected] 
  │   │ └── [email protected] 
  │   ├── [email protected] 
  │   ├─┬ [email protected] 
  │   │ └── [email protected] 
  │   ├── [email protected] 
  │   ├─┬ [email protected] 
  │   │ └── [email protected] 
  │   ├─┬ [email protected] 
  │   │ └── [email protected] 
  │   ├─┬ [email protected] 
  │   │ └── [email protected] 
  │   ├─┬ [email protected] 
  │   │ └─┬ [email protected] 
  │   │   └── [email protected] 
  │   └── [email protected] 
  ├─┬ [email protected] 
  │ ├─┬ [email protected] 
  │ │ └── [email protected] 
  │ └── [email protected] 
  ├─┬ [email protected] 
  │ └─┬ [email protected] 
  │   └── [email protected] 
  ├─┬ [email protected] 
  │ └── [email protected] 
  └─┬ [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ ├─┬ [email protected] 
    │ │ └── [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    ├─┬ [email protected] 
    │ └─┬ [email protected] 
    │   └── [email protected] 
    ├─┬ [email protected] 
    │ ├─┬ [email protected] 
    │ │ └── [email protected] 
    │ └── [email protected] 
    ├── [email protected] 
    └── [email protected] 

$ cat > test.js
"use strict";

const fs = require('fs');
const path = require('path');

var mongodbPrebuilt = require('mongodb-prebuilt');
var dbpath = path.join(__dirname, '..', '.db');
if (!fs.existsSync(dbpath)) {
  fs.mkdirSync(dbpath);
}
console.log("before");
mongodbPrebuilt.start_server({
  auto_shutdown: true,  // stop mongo when we exit
  args: {
    port: 27017,
    dbpath: dbpath,
  },
}, function(err) {
  if (err) {
    console.error("could not start mongo:", err);
  } else {
    console.log("started");
  }
});
console.log("after");
setInterval(function() { console.log("ping"); }, 2000);

$ node test.js
before
after
ping
ping
ping
...

The start_server callback is never called. Running with debugging I see this

$ DEBUG=* node test.js
before
  mongodb-prebuilt logpath is +0ms /var/folders/7h/wyw4jhd933z5jmqzsdx6r0sr0000gn/T/mongodb-prebuilt-1461836817846.log
  mongodb-prebuilt bin path: /Users/gregg/temp/delme-mongodb-test/node_modules/mongodb-prebuilt/dist/3.2.0/bin/ +2ms
  mongodb-prebuilt spawn +1ms /Users/gregg/temp/delme-mongodb-test/node_modules/mongodb-prebuilt/dist/3.2.0/bin/mongod --port 27017 --dbpath /Users/gregg/temp/.db --fork --logpath /var/folders/7h/wyw4jhd933z5jmqzsdx6r0sr0000gn/T/mongodb-prebuilt-1461836817846.log
  mongodb about to fork child process, waiting until server is ready for connections.
forked process: 54772
child process started successfully, parent exiting
 +743ms
  mongodb  +1ms
  mongodb-prebuilt starting mongokiller.js, ppid:54769  mongod pid:54772 +0ms
after
ping
ping
...

@greggman
Copy link

greggman commented May 2, 2016

Sorry if I'm confused. Looking at the code though I don't see how callback is/was ever called. Maybe I'm mis-understanding what's supposed to happen.

Looking in index.js I see start_server(opts, callback). Following the code callback is only used in a few places.

  • line 59 if installation fails
  • line 80 if there's an error spawning mongod

That's it. There's no use of callback in any other case so no way for callback to be called once mongod starts.

Am I mis-understanding?

@jadamgreen1010-zz
Copy link

@greggman No, I think you're right, and the new version doesn't address this.

Using the callback for everything would be nice, and it looks like it wouldn't take much, but it'd be a breaking change.

@greggman
Copy link

greggman commented May 2, 2016

Ok, but it's the example in the README so if that's not the way it's supposed to work maybe the README should change?

@cantremember
Copy link

the 4.x codebase used to return an EventEmitter from start_server, and you could listen to the 'mongoStarted' event (since the callback never got called on success)

it looks like the 5.x line no longer does this

@winfinit
Copy link
Contributor

winfinit commented Mar 8, 2017

there was a complete rewrite of this library, please use 6.x release

@winfinit winfinit closed this as completed Mar 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants