Skip to content

Commit 1263180

Browse files
bug symfony#50429 [Console] block input stream if needed (joelwurtz)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] block input stream if needed | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | n | Tickets | / | License | MIT | Doc PR | / When the input stream used in the question helper is not blocking, the default value is always used as the stream return false instead of waiting. In order to fix that, we force the stream to be in blocking state and go back to the old state after so other logic is not impacted by this change. I don't think making a test for that is possible without writing a lot of codes, as we need to have a stream that is not ready for this test, and make it ready later, given there is no async possible. it could be done with a fork or another process writing to a file **after** the question was asked so we do not block following tests when there is no failure, however i'm not sure if this is wanted ?. If you have a clean way to make a reproducible test for this bug i'm open to write it. Commits ------- 8ae36f3 [Console] block input stream if needed When the input stream used in the question helper is not blocking, the default value is always used as the stream return false. In order to fix that, we force the stream to be in blocking state and go back to the old state after so other logic is not impacted by this change
2 parents 3606499 + 8ae36f3 commit 1263180

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,18 @@ private function doAsk(OutputInterface $output, Question $question)
128128
}
129129

130130
if (false === $ret) {
131+
$isBlocked = stream_get_meta_data($inputStream)['blocked'] ?? true;
132+
133+
if (!$isBlocked) {
134+
stream_set_blocking($inputStream, true);
135+
}
136+
131137
$ret = $this->readInput($inputStream, $question);
138+
139+
if (!$isBlocked) {
140+
stream_set_blocking($inputStream, false);
141+
}
142+
132143
if (false === $ret) {
133144
throw new MissingInputException('Aborted.');
134145
}

0 commit comments

Comments
 (0)