-
Notifications
You must be signed in to change notification settings - Fork 50
Conversation
I'm also getting the error message "Error parsing command line: unrecognised option '--fork'" (windows), when I used the fix from above it worked again. |
@pibi, there are two reasons why fork was used, one is consistent reporting of child process status, so I didn't have to do bunch of catches, and second reason is to deprecate event emitter. I would like to see if there is a way to write a wrapper around mongod for windows, that would simulate interface of linux/osx, for example, it could be a "start /b" check on a child process, and then report back status that can be parsed by mongodb-prebuilt |
Ok, I can understand the event emitter deprecation reason. Maybe I don't understand the former reason because I'm using your project inside mockgoose to perform unit tests. For this use case '--fork' (daemon mode) is pretty useless. Well, I don't know a use case where I can use mongodb-prebuilt without a proper detach of mongod. |
It will detach, and spawn killer process that will take care of a mongod, otherwise in case of parent death, mongod would remain alive. Your unit tests should not care nor know about mongod spawning of with or without fork.
|
This makes no sense for me. You should use It seems that nodejs
yep, I agree. I was talking about the usage of this module. I have no visibility about its usage in different contexts, so from a "test point of view" |
@pibi there is somewhere a disconnect, and I am not sure where. mongod is not a short lived process, and if you would use spawnSync (which I am using) on mongod without --fork, node process will be blocked until command is not done executing. Now if you use just spawn, you have two issues, one is that you have to attach to output, and start parsing output from mongod to determine if service started successfully or not, and exit codes across platforms and mongod versions are not consistent, so you cannot rely on exit codes, we tried that already, if you go with parsing logs, that means you have to notify "something" (in this case Mockgoose) that database is started (or in failure case you have to notify mongodb-prebuilt). What fork does in mongod is: it start a process on the background, but it reports startup status and exit codes in a synchronous matter, i.e.: process doesnt exit until mongod is initiated. reason why you cannot just spawn, and go on with your life, is because you can get race condition even in a successful scenario, and have to implement retries on a client side: i.e.: if you spawned mongod, and it took longer to start, before connect call is being issued. Now in this retry scenario, it is not working also, in case there was a failure to start mongod, because client then would be retrying infinitely, unless there is a process to detect a failure of a startup, and try different port for example. now detached vs not detached, will not help you, if process simply dies, child process remains, for this you can setup a simple test where you spawnSync process (with or without detach), and kill -9 your parent process, then check your process tree for mongod. |
@winfinit first of all, thanks for sharing your thoughts with me. Race condition: this happens because you are not using callback (see #27) . Client should not try to connect until a successful callback is fired (and this is the reason behind my patch at mccormicka/Mockgoose#212) . About child process: As long as the parent exits or it is killed there's no way a child could survive, unless you use inherits/stream for stdio or detached. To be sure about that I just test these scenarios on windows/linux with this gist: https://gist.github.com/pibi/d6c90e23a9224164893cbe6882bc8b5c |
@pibi what are you demonstrating with above gists? issue is with killing a parent process, or if there is an exception that occurred within a parent process. so either one of those cases would leave 'yes' dormant:
output:
now about callback, I need to look at it closer, from what i've read on previous bugs, issue is that you are dealing with some of the code that i've restructured, or didn't complete to restructure, that resulted in bugs due to insufficient testing. one of those bugs is --fork and windows, which is separate problem from callback not being called, and all efforts of previous restructure were to block process until mongod started. I will scan through reported issues in Mockgoose sometime this week, because at the moment I feel that all of the fixes that are being suggested are not aligned with my original rewrite, and people are fixing or reversing original vision, however I haven't been active for some time, so I can't blame anyone for this but me. |
@winfinit yep, I know we are talking about many different issues here. About the gist, yep, they are used to test the various scenario on win and linux. I just test your snippet: here the results: Ubuntu, no detached:
Ubuntu, with detached ( var child = spawn('yes', { detached: true , stdio:'ignore'}); ):
windows (mingw) with detach:
windows (mingw) without detach:
windows, with detach (cmd and starting another long running node.js script) :
windows, without detach (cmd and starting another long running node.js script):
So, it seems you have a bug on your Mac! |
maybe related to nodejs/node#3596 |
@pibi not sure if comment meant to be witty, but it is not a bug on my mac, it is a behavior with OS X and/or BSD and nodeJS. I don't want to dig around right now, but I do remember seeing various bugs filed against nodejs for this exact behavior, and personally was able to reproduce this exact thing on linux distros. given that there is this behavior/bug, Mockgoose and mongodb-prebuilt would have to account for this, hence that is why i have a watchdog process, and would like to simulate --fork behavior on windows. |
@winfinit: oh, ok, now I understand your reasons, it's a quite weird approach if you trust POSIX behavior to be consistent and cross-platform (here should be libuv to enforce the "standard"). About the --fork simulation, I'm wondering how it could be different from btw, thanks a lot for the discussion and your work |
…fail when spawning processes (cf: winfinit#25, mongodb-js#25 & mccormicka/Mockgoose#207)
fork is not used anymore with most recent rewrite |
Mongod doesn't support --fork on Windows. so forcing it to true leads to errors (see mccormicka/Mockgoose#207 ). Without --fork spawnSync will block the event loop indefinitely.
So, here is a fix for both the issues.