mongodb-js / devtools-shared

Shared dependencies of Compass, the MongoDB extension for VSCode and mongosh
Other
14 stars 5 forks source link

mongodb-runner doesn't kill all instances #483

Open mtrezza opened 4 days ago

mtrezza commented 4 days ago

Bug Report

Current Behavior

When running mongodb-runner stop --all, the following error is thrown and the MongoDB instance is not stopped:

/node_modules/mongodb-runner/dist/cli.js:170
        throw err;
        ^

Error: kill ESRCH
    at process.kill (node:internal/process/per_thread:233:13)
    at MongoServer.close (/node_modules/mongodb-runner/dist/mongoserver.js:201:21)
    at /node_modules/mongodb-runner/dist/mongocluster.js:162:88
    at Array.map (<anonymous>)
    at MongoCluster.close (/node_modules/mongodb-runner/dist/mongocluster.js:162:61)
    at /node_modules/mongodb-runner/dist/runner-helpers.js:87:75
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 2)
    at async Object.stop (/node_modules/mongodb-runner/dist/runner-helpers.js:86:5)
    at async stop (/node_modules/mongodb-runner/dist/cli.js:121:9) {
  errno: -3,
  code: 'ESRCH',
  syscall: 'kill'
}

Node.js v18.18.2

Code/Gist

Expected Behavior/Code

MongoDB instance should be stopped, no error thrown.

Environment

Moumouls commented 4 hours ago

It seems that there is an issue with mongo stop all

here a server created

> mongodb-runner start -t standalone

Server started and running at mongodb://127.0.0.1:54879/
Run the following command to stop the instance:
mongodb-runner stop --id=1ef1f912-597f-4e2e-9f2c-c63d4ed99801

Then an error on mongo stop all

> mongodb-runner stop --all

/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb-runner/dist/cli.js:170
        throw err;
        ^

MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Topology.selectServer (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/sdam/topology.js:303:38)
    at async Topology._connect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/sdam/topology.js:196:28)
    at async Topology.connect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/sdam/topology.js:158:13)
    at async topologyConnect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/mongo_client.js:223:17)
    at async MongoClient._connect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/mongo_client.js:236:13)
    at async MongoClient.connect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/mongo_client.js:161:13)
    at async MongoClient.connect (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb/lib/mongo_client.js:322:16)
    at async MongoServer.withClient (/Users/antoinecormouls/Desktop/Repos/parse/parse-server/node_modules/mongodb-runner/dist/mongoserver.js:221:24)

The stop system seems to try to connect to a 27017 port but there is no instances on this port


Edit

I found that Mongo instances are referenced or stored globally, such as under: /Users/antoinecormouls/.mongodb/runner2. There are some ghost references, causing the system to try to connect to and close already-closed runners.