delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/02/19/04:52:08

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=EVcsEb136hQn+WOvGYhZxLJi9qOV00GdjhT7KJF4JQdXCBbJ0VpSb
vDfWhXb6mygjWeCVT+8Z6dDB9+jWKPkyh4lAsyneWnMPNn7gjyjfiH7JdaAkLgWA
ui6iVOptMQHP+1pL6AB/Z/7c1OkZblYKooTSTFpK4D8d2GQ3cv9AQM=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=GDDt1gFmja7cbkkrG2WlNGznxWk=; b=nOUqNyKESE2c1NzOFL/LOrVSUgFi
6sA3UOphioClBo6PJvwpHrP3/b86ZOv6cqoS0i8UCWZHnAJ+/cHikk9LhrqBAgHY
weiRrcYv74uLlO9USWXc9xBSQ4IAx6v0giq6/ipGxGhch6JYKwik5FCprG06aisT
GyR2TFgtbNBNuDE=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2
X-HELO: calimero.vinschen.de
Date: Thu, 19 Feb 2015 10:51:47 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Cc: Lasse Collin <lasse DOT collin AT tukaani DOT org>
Subject: Re: Clearing O_NONBLOCK from a pipe may lose data
Message-ID: <20150219095147.GC26084@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com, Lasse Collin <lasse DOT collin AT tukaani DOT org>
References: <20150218220859 DOT 1e8f8b19 AT tukaani DOT org>
MIME-Version: 1.0
In-Reply-To: <20150218220859.1e8f8b19@tukaani.org>
User-Agent: Mutt/1.5.23 (2014-03-12)

--32u276st3Jlj2kUU
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Feb 18 22:08, Lasse Collin wrote:
> (Please Cc me when replying, I'm not subscribed to the list.)
>=20
> Hi!
>=20
> I suspect that there is a bug in Cygwin:
>=20
> 1. Create a pipe with both ends in blocking mode (O_NONBLOCK
>    is not set).
> 2. The writer sets its end to non-blocking mode.
> 3. The writer writes to the pipe.
> 4. The writer restores its end of the pipe to blocking mode
>    before the reader has read anything from the pipe.
> 5. The writer closes its end of the pipe.
> 6. The reader reads from the pipe in blocking mode. The last
>    bytes written by the writer never appear at the reader,
>    thus data is silently lost.
>=20
> Omitting the step 4 above makes the problem go away.

I can imagine.  A few years back, when changing the pipe code to
using overlapped IO, we stumbled over a problem in Windows.  When
closing an overlapped pipe while I/O is still ongoing, Windows
simply destroys the pipe buffers without flushing the data to the
reader.  This is not much of a problem for blocking IO, but it
obviously is for non-blocking.

The workaround for this behaviour is this:  If the pipe is closed, and
this is the writing side of a nonblocking pipe, a background thread gets
started which keeps the overlapped structure open and continues to wait
for IO completion (i.e. the data has been sent to the reader).

However, if you switch back to blocking before closing the pipe, the
aforementioned mechanism does not kick in.

I can look into improving that at one point, but not soon.


Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--32u276st3Jlj2kUU
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJU5bIzAAoJEPU2Bp2uRE+g9mMQAKPyrTm8i3uJzlNeN1F7/1Js
0NQzCeucbyEYphkfliaccnKLPImek1wKZpCngSZKbYaKMlxXDcQORCFfESbJDD7o
/xFNDkdd+K56APYqHuQBo23Bb6WECoUj/WJC5U+uz1dWgWtIjMD4RJmJ+xE1Kh7d
0WmLpqnOa1v50rMMH0HZ1/10uNpxS1Tx10aNN4idhRc7AbQxSzirgOzRNgPlwWti
pt2gIe4d5KTNm/sXn5ec7puE9PPCVeb1onungY6wKFy0DVWVkbQStWpwS0o1SbPA
G5plf/27Ao0beADyPM1gFEEAT2KpFi4pxzas3pjAL7MP2ByOOrpPfF7RJUolqA3H
CwdxIckxa/uG0CNYqBqT5kf4+IFjs0WJRkXTNvwxItTVkSHx/Tc5SmdBeWbcHJCQ
LBDcsvA8TLHKsl1cZc+XNSPgEVIulZJzNgLPfAaK+J3LFKyzdt8/HJYOpDPpxrY5
Q2OlEMJVqcWRDvVPaSbEdVV1ac1p6kNjor9nUrRlD3OkosSyGqQg4oLkwMl3SfxW
Gg//ilwyPfWzH868KPeLzgpJRKLcDlasGPbrVuHNDC45vyXlY1OgGLCZyBSW66PA
eB9ekOpniwZNU+qLVsu61oPTOItU7oXplyNwwHlBm8ACkB2rrrN6Bm7OWVBO6T7K
6xT2r5SulSlW7WOFzzgN
=GymN
-----END PGP SIGNATURE-----

--32u276st3Jlj2kUU--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019