public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Cc: bf <bf2006a@yahoo.com>
Subject: Re: cygwin 3.3.x: another problem that may be related to pipes
Date: Mon, 15 Nov 2021 17:18:11 +0900	[thread overview]
Message-ID: <20211115171811.844dce9cce2b4d13262d64f2@nifty.ne.jp> (raw)
In-Reply-To: <115203324.649908.1636923059546@mail.yahoo.com>

On Sun, 14 Nov 2021 20:50:59 +0000 (UTC)
bf wrote:
> I've a shell script that processes several hundred xz-compressed text files with a pipeline of the form:
> 
> find . -depth -type f  ... -print0 | \
> xargs -0tI @ xzcat -- @ | \
> iconv --byte-subst='�' --unicode-subst='�' --widechar-subst='�' -f MS-ANSI -t UTF-8 -- | \
> grep ... \
> sed ... | \
> sort ... | \
> sort ...
> 
> . Since updating to cygwin 3.3.x (but not on cygwin 3.2.x) the script consistently fails when decompressing a portion of the files, resulting in lost data, and error messages of the form:
> 
> xzcat: (stdout): Write error: Bad address

Thanks for the report.
I could reproduce your problem and found the cause.

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?


From 2261c7d7df0173d2fb6755f6b9ccccf02b27015e Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Mon, 15 Nov 2021 12:30:53 +0900
Subject: [PATCH] Cygwin: pipe: Call CancelIo() if I/O is pending in
 nonblocking mode.

- Currently, handling for STATUS_PENDING in raw_read()/raw_write()
  in nonblocking mode is missing. This patch fixes the issue.

Addresses:
  https://cygwin.com/pipermail/cygwin/2021-November/249910.html
---
 winsup/cygwin/fhandler_pipe.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index 1ebf4de10..0de01befb 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -355,6 +355,9 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
 	  else
 	    status = io.Status;
 	}
+      else if (status == STATUS_PENDING)
+	/* CancelIo() if STATUS_PENDING in nonblocking mode. */
+	CancelIo (get_handle ());
       if (isclosed ())  /* A signal handler might have closed the fd. */
 	{
 	  if (waitret == WAIT_OBJECT_0)
@@ -538,6 +541,9 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
 	  else
 	    status = io.Status;
 	}
+      else if (status == STATUS_PENDING)
+	/* CancelIo() if STATUS_PENDING in nonblocking mode. */
+	CancelIo (get_handle ());
       if (isclosed ())  /* A signal handler might have closed the fd. */
 	{
 	  if (waitret == WAIT_OBJECT_0)
-- 
2.33.0

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

  reply	other threads:[~2021-11-15  8:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <115203324.649908.1636923059546.ref@mail.yahoo.com>
2021-11-14 20:50 ` bf
2021-11-15  8:18   ` Takashi Yano [this message]
     [not found]   ` <20211123002924.a7890a0e1fa58eebd69a6951@nifty.ne.jp>
     [not found]     ` <1790410068.674967.1637619810958@mail.yahoo.com>
2021-11-22 23:17       ` 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=20211115171811.844dce9cce2b4d13262d64f2@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=bf2006a@yahoo.com \
    --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).