-
Notifications
You must be signed in to change notification settings - Fork 7.3k
tests: fix race in test-http-curl-chunk-problem #9301
tests: fix race in test-http-curl-chunk-problem #9301
Conversation
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.
This should be backported to v0.10, but there are other issues for v0.10 (see http://jenkins.nodejs.org/job/node-review-windows-julien/DESTCPU=ia32,label=windows/lastBuild/tapTestReport/simple.tap-240/) in this test that require more changes, so I'll fix that for v0.10 in another PR. |
FYI - This test was failing consistently on one of our internal test machines, applying the patch resolved the issue. |
@mdawsonibm Thanks for the heads up! If you have some time to review the code change and if you think it's the best way to fix it, could you please add "LGTM" in a comment? Thanks again! |
/cc @joyent/node-coreteam. |
LGTM |
1 similar comment
LGTM |
Another solution to wait for the "close" event on the child process object. It's guaranteed to fire after both the process has exited and all the stdio streams are closed. But this works too - lgtm. |
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]>
Landed in io.js - nodejs/node@1009130 |
LGTM |
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#9301 PR-URL: nodejs#9301 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bert Belder <null>
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: #9301 PR-URL: #9301 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bert Belder <[email protected]>
@piscisaureus Indeed, that was my first solution, and then I thought that this one was more explicit. Thanks for bringing that up! |
Thank you, landed in d9a309f! |
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#9301 PR-URL: nodejs#9301 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bert Belder <[email protected]>
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.