cygwin 3.3.x: another problem that may be related to pipes

Ken Brown kbrown@cornell.edu
Mon Nov 15 13:57:43 GMT 2021


On 11/15/2021 8:01 AM, Corinna Vinschen wrote:
> [Redirected to cygwin-developers]
> 
> On Nov 15 17:18, Takashi Yano via Cygwin wrote:
>> raw_read()/raw_write() in fhandler_pipe.cc seems to need handling
>> of STATUS_PENDING in nonblocking mode.
>>
>> I also confirmed the following patch fixes the issue. However, I
>> am not very sure that this is the right thing.
>>
>> Corinna, Ken, what do you think?
> 
> I'm puzzled.  non-blocking pipes return STATUS_PENDING?  What on earth
> is that supposed to mean on non-blocking (as opposed to asynchronous)
> pipes?  The problem is that STATUS_PENDING theoretically requires
> to wait for... something, the pipe handle, perhaps, and then to check
> io.Status.

I noticed last week when I was debugging the XEmacs problem that NtReadFile 
occasionally returned STATUS_PENDING.  I commented on it here:

   https://cygwin.com/pipermail/cygwin/2021-November/249827.html

But I promptly forgot about it when that turned out not to be the problem for 
that bug.  My thought at the time was that we needed something like this:

diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index 9392a28c1..aaf09829d 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -336,9 +336,10 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
         break;
        status = NtReadFile (get_handle (), evt, NULL, NULL, &io, ptr,
                            len1, NULL, NULL);
-      if (evt && status == STATUS_PENDING)
+      if (status == STATUS_PENDING)
         {
-         waitret = cygwait (evt, INFINITE, cw_cancel | cw_sig);
+         /* Very short-lived in the non-blocking case. */
+         waitret = cygwait (evt ?: get_handle (), INFINITE, cw_cancel | cw_sig);
           /* If io.Status is STATUS_CANCELLED after CancelIo, IO has actually
              been cancelled and io.Information contains the number of bytes
              processed so far.

Takashi, does that fix the problem?

> Is it possible that nonblocking pipes need to be synchronous, i. e.,
> setting the FILE_SYNCHRONOUS_IO_NONALERT would fix that?

Ken


More information about the Cygwin-developers mailing list