[SERVER-20838] Exit code of MongoDB processes is unchecked in jstests starting their own clusters Created: 08/Oct/15  Updated: 12/Jan/17  Resolved: 19/Jan/16

Status: Closed
Project: Core Server
Component/s: Shell, Testing Infrastructure
Affects Version/s: 3.1.9
Fix Version/s: 3.3.1

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Jonathan Reams
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-4959 Check exit code when killing servers ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Build C (11/20/15), Build D (12/11/15), Build E (01/08/16), Build F (01/29/16)
Participants:

 Description   

_stopMongoProgram() returns the exit code of the process, which gets propagated by MongoRunner.stopMongod() and MongoRunner.stopMongos(). However, none of the tests or testing infrastructure actually check the return value. It'd be nice to assert that the exit code is zero (in situations where the MongoDB processes aren't expected to crash), but doing so is hampered by how the process can be terminated with a SIGKILL if it takes longer than a minute to shut down.

Tests that start their own MongoDB deployments currently do not fail when LeakSanitizer reports that there were memory leaks.

int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt) {
    ProcessId pid;
    int exitCode = 0;
    if (port > 0) {
        if (!registry.isPortRegistered(port)) {
            log() << "No db started on port: " << port << endl;
            return 0;
        }
        pid = registry.pidForPort(port);
    } else {
        pid = _pid;
    }
 
    kill_wrapper(pid, signal, port, opt);
 
    int i = 0;
    for (; i < 130; ++i) {
        if (i == 60) {
            log() << "process on port " << port << ", with pid " << pid
                  << " not terminated, sending sigkill" << endl;
            kill_wrapper(pid, SIGKILL, port, opt);
        }
        if (wait_for_pid(pid, false, &exitCode))
            break;
        sleepmillis(1000);
    }
    if (i == 130) {
        log() << "failed to terminate process on port " << port << ", with pid " << pid << endl;
        verify("Failed to terminate process" == 0);
    }
 
    registry.deleteProgram(pid);
    // FIXME I think the intention here is to do an extra sleep only when SIGKILL is sent to the
    // child process. We may want to change the 4 below to 29, since values of i greater than that
    // indicate we sent a SIGKILL.
    if (i > 4 || signal == SIGKILL) {
        sleepmillis(4000);  // allow operating system to reclaim resources
    }
 
    return exitCode;
}



 Comments   
Comment by Githook User [ 19/Jan/16 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-20838 stopMongod should throw if mongod exits abnormally
Branch: master
https://github.com/mongodb/mongo/commit/9db9a382296cd5ec3fcc80f7bb89eb7db0d65fc4

Generated at Thu Feb 08 03:55:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.