node-mongolian icon indicating copy to clipboard operation
node-mongolian copied to clipboard

temporary fix for issue 33

Open jaekwon opened this issue 13 years ago • 2 comments

this fix will become obsolete when the node-mongodb dependency gets removed, but here's a fix that worked for me in case others need it now.

jaekwon avatar Dec 20 '11 08:12 jaekwon

Is there some way we can build a test case for this? I'm not entirely convinced that the problem goes away with the new code branch.

marcello3d avatar Dec 22 '11 03:12 marcello3d

The problem is a collection of the following:

  1. 'server = new Server()' will call scanServer, which sends a command to 'admin'.
  2. my code happened to want to quit immediately after creating a Server (in the same event loop), because there were no indices to ensure.
  3. calling 'server.close()' immediately upon Server creation hangs because the 'admin' command from (1) didn't respond yet, which means taxman didn't have a chance to set .value.

Testing is not easy, the failure effect is that typical node scripts will hang (I guess because the server connection is open), whereas nodeunit may be forcing an exit() once all the test.done() have been called.

You can easily test hanging on the console with the following script.

var Mongolian = require('./mongolian')
var db = new Mongolian('mongo://localhost/mongolian_test', { log:false })
var hang = true

if (hang) {

  db.dropdatabase(function(error) {
  })
  db.server.close()

} else {

  db.dropdatabase(function(error) {
    db.server.close()
  })

}

jaekwon avatar Dec 25 '11 01:12 jaekwon