[SERVER-32872] _stopMongoProgram should error when passed a double port number Created: 24/Jan/18  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Shell, Testing Infrastructure
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 0
Labels: stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Tooling & Methods
Participants:

 Description   

Running the following in the shell:

_stopMongoProgram(-123456.789, 15, {})

or:

_stopMongoProgram(NaN, 15, {})

results in the shell terminating immediately with

Terminated: 15

and no other information. I think it ends up sending a SIGTERM to the running shell process. Instead we should validate that the passed port number is an integer.

Calls to _stopMongoProgram should be through the corresponding shell wrappers like MongoRunner.stopMongod. However, this did surface for me in real life when accidentally passing a DB object instead of a Mongo object, ala:

var mongod = MongoRunner.runMongod({});
var mongodb = mongod.getDB("test");
MongoRunner.stopMongod(mongodb); // should be "mongod"

MongoRunner.stopMongod validates that the passed object has the "port" and "pid" properties, But since the db object says it has any property (for collections) it gets through to the call of _stopMongoProgram and passes NaN as the PID.

This could be fixed just to validate that the passed port is an integer.

Note that stopMongoProgramByPid doesn't have this issue. It gives an invariant failure indicating the PID is invalid:

Invariant failure isPidRegistered(pid) src/mongo/shell/shell_utils_launcher.cpp 173

Another note. When testing these functions, tread carefully. Don't run stopMongoProgramByPid on a floating point that rounds down to 1 as you'll likely need to restart your computer... speaking from experience.



 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Generated at Thu Feb 08 04:31:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.