Skip to content

Conversation

sergiodj
Copy link

The idiom used in the readStdin function from src/Utils/CLI.php is not
entirely error-prone: marking stdin as non-blocking and then reading
from it can lead to racy scenarios where we are not able to catch
what's being fed to the program. This can be seen very frequently on
s390x, where a loop like this:

$ while echo "invalid query" | /usr/bin/php7.4 /path/to//highlight-query; do sleep 1; done;

will lead to failures once on every few runs (as can be seen in the
description of issue #309).

This commit implements the more robust method which uses stream_select
to wait for stdin to become available, but resorts to a sensible
timeout value (0.2 seconds) which will prevent the blocking from
happening.

I tested this patch extensively on s390x and amd64, and noticed that
the non-determinism is gone.

Signed-off-by: Sergio Durigan Junior sergio.durigan@canonical.com

@sergiodj sergiodj force-pushed the fix-309-use-stream-select-instead-non-blocking-stdin branch 2 times, most recently from fd3f2bd to 21cb031 Compare August 27, 2020 00:28
@williamdes williamdes changed the base branch from master to QA August 27, 2020 07:26
The idiom used in the readStdin function from src/Utils/CLI.php is not
entirely error-prone: marking stdin as non-blocking and then reading
from it can lead to racy scenarios where we are not able to catch
what's being fed to the program.  This can be seen very frequently on
s390x, where a loop like this:

  $ while echo "invalid query" | /usr/bin/php7.4 /path/to//highlight-query; do sleep 1; done;

will lead to failures once on every few runs (as can be seen in the
description of issue phpmyadmin#309).

This commit implements the more robust method which uses stream_select
to wait for stdin to become available, but resorts to a sensible
timeout value (0.2 seconds) which will prevent the blocking from
happening.

I tested this patch extensively on s390x and amd64, and noticed that
the non-determinism is gone.

Signed-off-by: Sergio Durigan Junior <sergio.durigan@canonical.com>
@williamdes williamdes force-pushed the fix-309-use-stream-select-instead-non-blocking-stdin branch from 21cb031 to 5419487 Compare August 27, 2020 07:29
Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes williamdes self-assigned this Aug 27, 2020
@williamdes williamdes added this to the 4.6.2 milestone Aug 27, 2020
@codecov
Copy link

codecov bot commented Aug 27, 2020

Codecov Report

Merging #312 into QA will increase coverage by 0.11%.
The diff coverage is 86.51%.

Impacted file tree graph

@@             Coverage Diff              @@
##                 QA     #312      +/-   ##
============================================
+ Coverage     99.62%   99.73%   +0.11%     
- Complexity     1860     1899      +39     
============================================
  Files            63       63              
  Lines          4523     4581      +58     
============================================
+ Hits           4506     4569      +63     
+ Misses           17       12       -5     
Impacted Files Coverage Δ Complexity Δ
src/Components/CreateDefinition.php 100.00% <ø> (ø) 43.00 <0.00> (ø)
src/Components/DataType.php 100.00% <ø> (ø) 17.00 <0.00> (ø)
src/Components/Expression.php 100.00% <ø> (ø) 90.00 <0.00> (ø)
src/Components/IntoKeyword.php 100.00% <ø> (ø) 34.00 <0.00> (ø)
src/Components/UnionKeyword.php 100.00% <ø> (ø) 2.00 <0.00> (ø)
src/Parser.php 100.00% <ø> (ø) 31.00 <0.00> (ø)
src/TokensList.php 100.00% <ø> (ø) 27.00 <0.00> (ø)
src/UtfString.php 100.00% <ø> (ø) 24.00 <0.00> (ø)
src/Utils/BufferedQuery.php 100.00% <ø> (ø) 67.00 <0.00> (ø)
src/Context.php 94.82% <57.14%> (-2.40%) 82.00 <4.00> (+5.00) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f31612...c862a10. Read the comment docs.

@williamdes williamdes merged commit 0770895 into phpmyadmin:QA Aug 27, 2020
@williamdes
Copy link
Member

Merged into QA as 0770895 and into master as 29ce64e

@williamdes
Copy link
Member

Thank you so much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants