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:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=dZpA760/l2oG5+3R SXtQjfFY8AuLV6rMlXOS4grmWKMn1Pdddl1iyAS5fl7wkBdnDvMryKlIDkQQblM2 cOiidYXf+OpF3Ic5Pa7GjFuhgnulr+uaqKw5QG7Pp3eH5c1sGmtHG/eKMXIZlvOF W9vORWzQOwX7vfgGrt/kmRfrRUo= 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:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=default; bh=PEtkfUdzJyvPmmY6oQORM3 fXBLM=; b=TB/DGiq0mtgOk43OG/Anzv+dbI7/7dW01OGWvWdq2f3mixLtymSZI9 lkMyDznKukuAPMf0chtMVQV4XIsZhzLhHaprJg+p7qwVJdT85YTnzJ6JYl9XNE+a 5AC4A59zqsYzePCNhlokeGDBfwTOUzq2A8MhfCLmcKsiojcXc9Egc= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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=3.2 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_BODY_URIBL_PCCC,KAM_FROM_URIBL_PCCC,KAM_THEBAT,RCVD_IN_JMF_BL,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: smtp.ht-systems.ru Date: Fri, 20 Feb 2015 02:47:00 +0300 From: Andrey Repin Reply-To: cygwin AT cygwin DOT com Message-ID: <145631367.20150220024700@yandex.ru> To: Thomas Wolff , cygwin AT cygwin DOT com Subject: Re: Clearing O_NONBLOCK from a pipe may lose data In-Reply-To: <54E660F1.3040509@towo.net> References: <20150218220859 DOT 1e8f8b19 AT tukaani DOT org> <20150219095147 DOT GC26084 AT calimero DOT vinschen DOT de> <54E660F1 DOT 3040509 AT towo DOT net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Greetings, Thomas Wolff! > Am 19.02.2015 um 10:51 schrieb Corinna Vinschen: >> On Feb 18 22:08, Lasse Collin wrote: >>> (Please Cc me when replying, I'm not subscribed to the list.) >>> >>> Hi! >>> >>> I suspect that there is a bug in Cygwin: >>> >>> 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. >>> >>> 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. > Could not "switching back to blocking" simply be handled like closing as > far as the waiting is concerned, > thus effectively flushing the pipe buffer? You can't "just flush" it, if the receiving end isn't reading from it. -- WBR, Andrey Repin (anrdaemon AT yandex DOT ru) 20.02.2015, <02:46> Sorry for my terrible english... -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple