public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: scp stalls on uploading in cygwin 3.5 current master.
Date: Sat, 26 Aug 2023 04:29:24 +0900	[thread overview]
Message-ID: <20230826042924.53b49a9f8372a9196a151425@nifty.ne.jp> (raw)
In-Reply-To: <ZOiHkCWY7PK3livD@calimero.vinschen.de>

Hi Corinna,

On Fri, 25 Aug 2023 12:50:56 +0200
Corinna Vinschen wrote:
> On Aug 25 17:48, Takashi Yano via Cygwin wrote:
> > This did not help. I looked into this deeper and noticed that:
> > 1) _win32_select() sometimes returns 0.
> > 2) If _win32_select() returns 0, WaitForMultipleObjects(..., INFINITE)
> >    is called in thread_socket().
> > 3) WaitForMultipleObjects() sometimes does not return for FD_WRITE
> >    for unknown reason.
> > This causes the stall.
> 
> So the situation is that the network event handling returned FD_WRITE,
> because it always returns FD_WRITE as long as a non-blocking send()
> function didn't explicitely fail due to buffer overrun.
> 
> However, _win32_select will notice that the buffer is full, so it
> does not return 1, but 0.  I e., the socket is not ready for writing.
> 
> Now you're saying that it's possible that the following WFMO will
> never return?
> 
> That would mean that the FD_WRITE event won't be triggered again because
> it already *had* been triggered and the only way to re-enable it is to
> call one of the send() functions (see
> https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect)
> 
> I don't have an answer to this problem yet.
> 
> Can we use send(sock, "", 0) to reenable FD_WRITE, perhaps?

Your idea seems to work. The following patch looks to solve the issue.
Is it supposed to be any side effect()?

diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 7b9473849..443f95e68 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -1824,8 +1824,16 @@ thread_socket (void *arg)
     {
       for (select_record *s = si->start; (s = s->next); )
 	if (s->startup == start_thread_socket)
-	  if (peek_socket (s, false))
-	    event = true;
+	  {
+	    if (peek_socket (s, false))
+	      event = true;
+	    else if (s->write_selected)
+	      {
+		/* Retrigger WSA socket event */
+		fhandler_socket_wsock *fh = (fhandler_socket_wsock *) s->fh;
+		fh->write ("", 0);
+	      }
+	  }
       if (!event)
 	for (int i = 0; i < si->num_w4; i += MAXIMUM_WAIT_OBJECTS)
 	  switch (WaitForMultipleObjects (MIN (si->num_w4 - i,


-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

  parent reply	other threads:[~2023-08-25 19:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 21:05 Takashi Yano
2023-08-24  3:31 ` Takashi Yano
2023-08-24  8:59   ` Corinna Vinschen
2023-08-25  8:48     ` Takashi Yano
2023-08-25 10:50       ` Corinna Vinschen
2023-08-25 12:08         ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-25 12:23           ` Corinna Vinschen
2023-08-25 13:19             ` Corinna Vinschen
2023-08-25 23:27               ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-26 13:52                 ` Corinna Vinschen
2023-08-26 14:15                   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-26 14:34                     ` Corinna Vinschen
2023-08-25 19:29         ` Takashi Yano [this message]
2023-08-26 14:08           ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-26 23:41             ` Takashi Yano
2023-08-28 13:37               ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-28 13:46                 ` Takashi Yano
2023-08-28 14:07                   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-08-28 14:20                     ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230826042924.53b49a9f8372a9196a151425@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).