-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-16889: stream_select() timeout useless for pipes on Windows
Pipes are blocking on Windows, but `php_select()` always returns them as ready for read/write. This renders the `stream_select()` timeout useless, what can cause a following read to block for a very long time. While there is no general fix (and least not within reach for a stable version), we can at least cater to the important case of read pipes by peeking the pipe to check whether data is available. If there is none, we do not add the handle to the read set. We need to fix a couple of tests cases: * bug60692.phpt and bug64770.phpt assume that at least the stdin and stdout pipes are always selected as readable, and that the select call will not change their order. We're being more defensive now. * the potentials warnings of bug49936_win32.phpt need to be suppressed, like it has been done earlier for the POSIX variant of this test case[1]. Possibly this test case should be dropped altogether[2]. [1] <c884d37> [2] <2c6b85f> Closes GH-16917.
- Loading branch information
Showing
6 changed files
with
49 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
GH-16889 (stream_select() timeout useless for pipes on Windows) | ||
--FILE-- | ||
<?php | ||
$desc = [ | ||
["pipe", "r"], | ||
["pipe", "w"], | ||
["pipe", "w"], | ||
]; | ||
// open process which won't produce output for 10s | ||
$proc = proc_open([PHP_BINARY, "-r", "sleep(10); echo 'finish';"], $desc, $pipes); | ||
$read = [$pipes[1]]; | ||
$write = null; | ||
$except = null; | ||
$time0 = microtime(true); | ||
// select STDOUT pipe of process for 1ms | ||
if (stream_select($read, $write, $except, 0, 1000)) { | ||
var_dump(fread($read[0], 1)); | ||
} | ||
// avoid blocking of finishing the test process | ||
proc_terminate($proc); | ||
$time1 = microtime(true); | ||
var_dump($time1 - $time0 < 1); | ||
?> | ||
--EXPECT-- | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters