Commit dd4ce2e
committed
Cygwin: pipe: Fix unexpected blocking mode change by pipe_data_available()
ipipe_data_available() is called from raw_write(). If the pipe is in
real_non_blocking_mode at that time, calling pipe_data_available()
can, in some cases, inadvertently revert the pipe to blocking mode.
Here is the background: pipe_data_available() checks the amount of
writable space in the pipe by calling NtQueryInformationFile() with
the FilePipeLocalInformation parameter. However, if the read side of
the pipe is simultaneously consuming data with a large buffer,
NtQueryInformationFile() may return 0 for WriteQuotaAvailable.
As a workaround for this behavior, pipe_data_available() temporarily
attempts to change the pipe-mode to blocking. If the pipe contains
data, this operation fails-indicating that the pipe is full. If it
succeeds, the pipe is considered empty. The problem arises from the
assumption that the pipe is always in real blocking mode before
attempting to flip the mode. However, if raw_write() has already set
the pipe to non-blocking mode due to its failure to determine available
space, two issues occur:
1) Changing to non-blocking mode in pipe_data_available() always
succeeds, since the pipe is already in non-blocking mode.
2) After this, pipe_data_available() sets the pipe back to blocking
mode, unintentionally overriding the non-blocking state required
by raw_write().
This patch addresses the issue by having pipe_data_available() check
the current real blocking mode, temporarily flip the pipe-mode and
then restore the pipe-mode to its original state.
Addresses: git-for-windows/git#5682 (comment)
Fixes: 7ed9adb ("Cygwin: pipe: Switch pipe mode to blocking mode by default")
Reported-by: Andrew Ng <[email protected]>
Reviewed-by: Johannes Schindelin <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
(cherry picked from commit 940dbeffa7134dcd0795bd146f60edac3548e32e)1 parent 1722f12 commit dd4ce2e
File tree
3 files changed
+9
-7
lines changed- winsup/cygwin
- fhandler
- local_includes
3 files changed
+9
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
330 | 329 | | |
331 | 330 | | |
332 | 331 | | |
| |||
453 | 452 | | |
454 | 453 | | |
455 | 454 | | |
456 | | - | |
457 | 455 | | |
458 | 456 | | |
459 | 457 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1203 | 1203 | | |
1204 | 1204 | | |
1205 | 1205 | | |
| 1206 | + | |
1206 | 1207 | | |
1207 | 1208 | | |
1208 | 1209 | | |
| |||
1212 | 1213 | | |
1213 | 1214 | | |
1214 | 1215 | | |
| 1216 | + | |
| 1217 | + | |
1215 | 1218 | | |
1216 | 1219 | | |
1217 | 1220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | | - | |
| 648 | + | |
| 649 | + | |
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
657 | 658 | | |
658 | | - | |
| 659 | + | |
659 | 660 | | |
660 | 661 | | |
661 | 662 | | |
662 | 663 | | |
663 | 664 | | |
664 | | - | |
665 | | - | |
| 665 | + | |
| 666 | + | |
666 | 667 | | |
667 | 668 | | |
668 | 669 | | |
| |||
0 commit comments