seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
926 stars 163 forks source link

Close client rather than use process.exit in cli #415

Open nholik opened 2 years ago

nholik commented 2 years ago

When using this as a library in order to use via a CI process, all of the commands that interact with the database would hang indefinitely.

After reviewing the main CLI code in https://github.com/seppevs/migrate-mongo/blob/master/bin/migrate-mongo.js I noticed that process.exit was being used in all these cases. For my needs, a clean exit can happen by making sure to do a close on the client object, which then allows the process to exit normally without forcing it.

Specifically, you can see here https://github.com/seppevs/migrate-mongo/blob/master/bin/migrate-mongo.js#L75 and https://github.com/seppevs/migrate-mongo/blob/master/bin/migrate-mongo.js#L96 both interact with a connection and have process.exit where as the create command which requires no connection does not need this pattern to stop https://github.com/seppevs/migrate-mongo/blob/master/bin/migrate-mongo.js#L48

My recommendation after observing this, which I can try my hand at a recommend PR if you'd like, would be to follow the same pattern in the CLI as I found where calling client.close will eliminate the need to force an exit.

rabih commented 2 years ago

I am experiencing a similar issue with our CI process around this and was fortunate to see this issue. @seppevs thoughts?