Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-32872

_stopMongoProgram should error when passed a double port number

    XMLWordPrintable

    Details

      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.

        Attachments

          Activity

            People

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM)
            Reporter:
            kevin.albertson Kevin Albertson
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: