Skip to content

Commit cbe555e

Browse files
committed
Fix SSH hangs
It was reported in git-for-windows/git#5199 that as of v3.5.4, cloning or fetching via SSH is hanging indefinitely. Bisecting the problem points to 555afcb (Cygwin: select: set pipe writable only if PIPE_BUF bytes left, 2024-08-18). That commit's intention seems to look at the write buffer, and only report the pipe as writable if there are more than one page (4kB) available. However, the number that is looked up is the number of bytes that are already in the buffer, ready to be read, and further analysis shows that in the scenario described in the report, the number of available bytes is substantially below `PIPE_BUF`, but as long as they are not handled, there is apparently a dead-lock. Since the old logic worked, and the new logic causes a dead-lock, let's essentially revert 555afcb (Cygwin: select: set pipe writable only if PIPE_BUF bytes left, 2024-08-18). Note: This is not a straight revert, as the code in question has been modified subsequently, and trying to revert the original commit would cause merge conflicts. Therefore, the diff looks very different from the reverse diff of the commit whose logic is reverted. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1e8cf1a commit cbe555e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

winsup/cygwin/select.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ peek_pipe (select_record *s, bool from_select)
776776
}
777777
ssize_t n = pipe_data_available (s->fd, fh, h, PDA_SELECT | PDA_WRITE);
778778
select_printf ("write: %s, n %d", fh->get_name (), n);
779-
gotone += s->write_ready = (n >= PIPE_BUF);
779+
gotone += s->write_ready = (n > 0);
780780
if (n < 0 && s->except_selected)
781781
gotone += s->except_ready = true;
782782
}
@@ -990,7 +990,7 @@ peek_fifo (select_record *s, bool from_select)
990990
ssize_t n = pipe_data_available (s->fd, fh, fh->get_handle (),
991991
PDA_SELECT | PDA_WRITE);
992992
select_printf ("write: %s, n %d", fh->get_name (), n);
993-
gotone += s->write_ready = (n >= PIPE_BUF);
993+
gotone += s->write_ready = (n > 0);
994994
if (n < 0 && s->except_selected)
995995
gotone += s->except_ready = true;
996996
}
@@ -1416,7 +1416,7 @@ peek_pty_slave (select_record *s, bool from_select)
14161416
{
14171417
ssize_t n = pipe_data_available (s->fd, fh, h, PDA_SELECT | PDA_WRITE);
14181418
select_printf ("write: %s, n %d", fh->get_name (), n);
1419-
gotone += s->write_ready = (n >= PIPE_BUF);
1419+
gotone += s->write_ready = (n > 0);
14201420
if (n < 0 && s->except_selected)
14211421
gotone += s->except_ready = true;
14221422
}

0 commit comments

Comments
 (0)