Skip to content

Commit 1009130

Browse files
Julien Gillipiscisaureus
Julien Gilli
authored andcommitted
tests: fix race in test-http-curl-chunk-problem
This test setups two event listeners: one on a child process' exit event , another for the same child process' stdandard output's 'data' event. The data even listener writes to a stream, and the exit event listener ends it. Because the exit event can be emitted before the data event, there is a chance that something will be written to the stream after it's ended, and that an error is thrown. This change makes the test end the stream in the listener for the child process' standard output's end event, which is guaranteed to be emitted after the last data event, thus avoiding the race. PR: nodejs/node-v0.x-archive#9301 Reviewed-by: Bert Belder <[email protected]> Reviewed-by: Michael Dawson <[email protected]> Reviewed-by: Colin Ihrig <[email protected]>
1 parent 6433ad1 commit 1009130

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/parallel/test-http-curl-chunk-problem.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ var server = http.createServer(function(req, res) {
4848
res.write(data);
4949
});
5050

51+
cat.stdout.on('end', function onStdoutEnd() {
52+
res.end();
53+
});
54+
5155
// End the response on exit (and log errors)
5256
cat.on('exit', function(code) {
5357
if (code !== 0) {
5458
console.error('subprocess exited with code ' + code);
5559
process.exit(1);
5660
}
57-
res.end();
5861
});
5962

6063
});

0 commit comments

Comments
 (0)