[SERVER-25076] shell output from exited programs remains after clearing Created: 14/Jul/16  Updated: 26/Jul/16  Resolved: 20/Jul/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.7
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Zach Snow Assignee: Matt Cotter
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-22992 wait_for_pid() function in shell_util... Closed
Operating System: ALL
Steps To Reproduce:

I wrote a simple script to reproduce this:

var text = "";
for (var i = 1; i <= 10; i++) {
  text += "Test line #" + i + "\n";
}
var startTime = new Date();
for (i = 1; i < 100000; i++) {
  var exitCode = runMongoProgram("echo", text);
  assert.eq(0, exitCode);
  assert.neq("", rawMongoProgramOutput(), "got an exit code but there's no output");
  clearRawMongoProgramOutput();
  var remainingText = rawMongoProgramOutput();
  if (remainingText !== "") {
    var timeTaken = (new Date() - startTime) / 1000;
    var msg = "still text remaining!\ntook "+i+" tries and "+timeTaken+" seconds\ntext remaining: '"+remainingText+"'";
    assert(false, msg);
  }
}

Saving that script to a file and running it with the mongo shell eventually fails:

assert failed : still text remaining!
took 15648 tries and 38.383 seconds
text remaining: 'sh51568| Test line #3
'

I have seen it fail in the same way in as little as one second. It has also failed occasionally on the line which asserts that the echo produces some output after it has exited.

Sprint: Platforms 18 (08/05/16)
Participants:

 Description   

The output of a program after a program exits does not always clear out after calling clearRawMongoProgramOutput.

This issue causes some jstests in mongo-tools to fail intermittently. They are being rewritten to work around this issue.



 Comments   
Comment by Matt Cotter [ 20/Jul/16 ]

Hi zach.snow,

Thanks for the report. Your code reproduces the error for me too, but after digging into it I think it's misdiagnosed – the real issue is that the runMongoProgram is exiting before the output from the forked process is fully written to the buffer. This script should work assuming the forked PID's are the same length (which they are on my machine ), but it fails even faster:

var text = "";
for (var i = 1; i <= 10; i++) {
    text += "Test line #" + i + "\n";
}
 
var exitCode = runMongoProgram("echo", text);
assert.eq(0, exitCode);
var expectedLen = rawMongoProgramOutput().split('\n').length;
clearRawMongoProgramOutput();
 
var startTime = new Date();
for (i = 1; i < 100000; i++) {
    var exitCode = runMongoProgram("echo", text);
    assert.eq(0, exitCode);
    var outputText = rawMongoProgramOutput();
    assert.neq("", outputText, "got an exit code but there's no output");
    assert.eq(expectedLen, outputText.split('\n').length, "program exited before done writing to buffer");
    clearRawMongoProgramOutput();
}

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