[SERVER-22992] wait_for_pid() function in shell_utils_launcher.cpp doesn't wait for program output to finish being consumed Created: 07/Mar/16  Updated: 24/May/17  Resolved: 12/Oct/16

Status: Closed
Project: Core Server
Component/s: Shell, Testing Infrastructure
Affects Version/s: None
Fix Version/s: 3.4.0-rc1

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: platforms-hocr
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-25076 shell output from exited programs rem... Closed
Gantt Dependency
has to be done before SERVER-26601 Remove assert.soon wrappers around ra... Closed
Related
is related to SERVER-19776 wrap rawMongoProgramOutput in assert.... Closed
is related to SERVER-22821 assert in lock_file_fail_to_open.js s... Closed
is related to SERVER-23829 Logs from mongos started by the mongo... Closed
is related to SERVER-25335 0002 umask yields world-readable .dbs... Closed
is related to SERVER-22737 make exit_logging.js more robust Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.2
Steps To Reproduce:

(function() {
    var lineContents = "a\n";
    var numLines = 1000;
 
    // run('echo', ...) will produce 'numLines' of output and block until the program exits.
    var exitCode = run("echo", lineContents.repeat(numLines));
    var output = rawMongoProgramOutput();
 
    assert.eq(0, exitCode);
 
    // The program runner includes an extra trailing newline in the output.
    assert.eq(numLines, output.split(lineContents).length - 1,
              "didn't wait for program's output buffer to finish being consumed");
})();

Sprint: Platforms 18 (08/05/16), Platforms 2016-08-26, Platforms 2016-09-19, Platforms 2016-10-10, Platforms 2016-10-31
Participants:
Linked BF Score: 27

 Description   

Some tests rely on being able to call _runMongoProgram() or _stopMongoProgram() and then make assertions about the program's output using rawMongoProgramOutput(). However, while the process may have exited, the code does not wait for all of the program's output to have been consumed from the pipe and for ProgramOutputMultiplexer::appendLine() to have been called on it.

BSONObj RunMongoProgram(const BSONObj& a, void* data) {
    ProgramRunner r(a);
    r.start();
    stdx::thread t(r);
    t.detach();
    int exit_code = -123456;  // sentinel value
    wait_for_pid(r.pid(), true, &exit_code);
    registry.deleteProgram(r.pid());
    return BSON(string("") << exit_code);
}



 Comments   
Comment by Githook User [ 13/Oct/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-22992 only declare _createProcessMtx on windows
Branch: master
https://github.com/mongodb/mongo/commit/e4307bfbe188cd6e85cf1e984db4ac5b8701c042

Comment by Githook User [ 12/Oct/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-22992 waiting on forked process also waits on consuming output
Branch: master
https://github.com/mongodb/mongo/commit/7b58433eec6437176f16ab4955b20c33a772aae8

Comment by Max Hirschhorn [ 07/Mar/16 ]

FWIW, The wrapper around subprocess.Popen() that resmoke.py uses internally does wait for the output to finish being consumed.

def wait(self):
    """
    Waits until the process has terminated and all output has been
    consumed by the logger pipes.
    """
 
    return_code = self._process.wait()
 
    if self._stdout_pipe:
        self._stdout_pipe.wait_until_finished()
    if self._stderr_pipe:
        self._stderr_pipe.wait_until_finished()
 
    return return_code

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