X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAAD2385F024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1585590272; bh=GqfdBZNSQOmVLCihhrkh8oLSFLtFjx6YjbHRKTzbebg=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FxAJSJqGD93hipW0dqQ3IKOT0tlyI7G7QqeNaoLnAwwxXmZSrfaDCGZBB/6ZKljMX mtqJvLoz8SHQ6RMGgRDNtDDzr2DyIGMR662yBgelRAHoIgNdUIXWW3waxAQbd0tYIh Zw2vx1EAzWeQVGZtlfBuMwHv4yzArqX4P8tW+bx8= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A2CAA385B836 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lStby2l6zdzZ4bU6UfQ0CgyPGiBzdgXrNHl/i0nesvnNxHixlCS/NbE1qgi5HEK5egNnJOSMmd9fQK4T+NYIiMzf8YIfw1wEqJvwxDgguMk/dQ5cGXxp4okvkrcH1psFKtRoyiMcdra9AbFA6qVpMouhpUcqrcqfv2LnKbrjY6p6bBIs/DBb5T9akAWiM6QOdyeSDrsNXUgbjAkWmb/Z9L24h++b/WiZG9YWUc8oZzQcNzsc5wZr1PwBnDOtHrBsI8msHBI4329in0J1m5UYqg44and8HfahYOnc5d0AmHIHOEMVoocAFNu9N87H5zL8H0zK8JSTHyGdNBb/jFgVXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zc0LVxiXGQesCV65bQ/eFRiQHCTCw9Fnzv1yobxiTfE=; b=CK4HAppnRQ8W6suoLuX6R6XuR1xP2RrGvwf1Dg5Ga6Rb8E7Z50MgMsfivSVRn5v5AtMfLxwRl1fLevLdJI/+dYHcVni815+5xJ9/KqCgal24U5NOyd6uLesTjnviJssTrsdGl6Zy2GHTYp4P+pBwtZDC2aQdOddGzp5lB62TE9KCT3Z9T+FMJWz9rESkYLlFZLYAHv/+YCGkyF5e47u5/7szb9M2Qu9fEzSc7gOXd1eG/2xV9r0Fi64KaJeRFrXcBxPHHozfF/mBGKN/jcDklWYbl2MosQWW9X1L3M4ZObcoo0Ruz/kJIJbtV0yEZgtz/WeBkV+CPCbJTETYFkGvQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none Subject: Re: Sv: Sv: Sv: Sv: Named pipes and multiple writers To: sten DOT kristian DOT ivarsson AT gmail DOT com References: <1b1401d60296$2769e690$763db3b0$@gmail.com> <716e2076-f607-454e-2723-937c3959e2a3 AT cornell DOT edu> <18be01d602ab$0bbfca30$233f5e90$@gmail.com> <35b43b59-6410-f21f-710c-385e39cbae0b AT cornell DOT edu> <005201d603ba$2bc8ab20$835a0160$@gmail.com> <472d1df6-531a-ebd7-4ffa-583a06e270ff AT cornell DOT edu> <00b901d60447$7ecb4c50$7c61e4f0$@gmail.com> <00e001d604f9$d0aa0720$71fe1560$@gmail.com> <8c6c5655-c162-8361-9f44-376bbd7cf114 AT cornell DOT edu> Message-ID: <3fe06192-7300-382a-8c98-f1bc2ff81e36@cornell.edu> Date: Mon, 30 Mar 2020 13:44:24 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------3490EC22AEDD2AA7601603DD" Content-Language: en-US X-ClientProxiedBy: CH2PR08CA0016.namprd08.prod.outlook.com (2603:10b6:610:5a::26) To DM6PR04MB6075.namprd04.prod.outlook.com (2603:10b6:5:127::31) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.0.17] (68.175.129.7) by CH2PR08CA0016.namprd08.prod.outlook.com (2603:10b6:610:5a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.20 via Frontend Transport; Mon, 30 Mar 2020 17:44:26 +0000 X-Originating-IP: [68.175.129.7] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16d5d3ad-db27-468d-96cb-08d7d4d1fe0a X-MS-TrafficTypeDiagnostic: DM6PR04MB5403: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-Forefront-PRVS: 0358535363 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR04MB6075.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10019020)(4636009)(366004)(376002)(346002)(136003)(396003)(39860400002)(26005)(16526019)(53546011)(16576012)(186003)(66556008)(31696002)(66946007)(66476007)(86362001)(6916009)(66616009)(316002)(31686004)(4326008)(786003)(33964004)(5660300002)(235185007)(52116002)(75432002)(6486002)(36756003)(478600001)(81156014)(2906002)(8936002)(81166006)(2616005)(8676002)(956004); DIR:OUT; SFP:1102; Received-SPF: None (protection.outlook.com: cornell.edu does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U3TRIfoBmYcovnEO6Ylsk2ptwwm3Po+xA8ulhRm3Z40//LAiajTnPEJOsbgZky3cA+4WAPPBl+T2BahdcqDhYyv8VNMzhzz1gvA+heSDuuqIN/99ZNXeAENAvznhzuYCUDQAziQpVxfeCXeCg3bN57dDDyD3CfJWvnybweu2FVUXkhHcZTyCYiCAy1gLEDR2Ahhx88rnIsoMbU+MzBqj6Ksb10XBefvNfCbfFwKo2OqNsrJwRDcDQRGDi+YI3B+s2pJy5+ccrdUe1wi0NVfwJg9W320fTXA0P5Q7p+icIUy+yT/w3H7Zu189SYrWxZcA7ZacgleEwjcXI1NcFO36lgAkoyZ0Z1GBZbWmsg3GkGaKSxCJV6G2HDbZxd2llEW6izgoSlz1dshDhRbU4R/N98z+VrOt4N4HYO/fn1lLu0H3iJY497AnKaYE6JPwzZqJ X-MS-Exchange-AntiSpam-MessageData: s9V0VeQiTsJwPAPkvi+IgOnIaq6Ps2Rzk6+t73azLobVuLEUOEtlraxEbfOPFMeVGy4vzATNegoFRCJiS1xYAB5j10VpWlZQwdunLv0wFwafzBjVOo/1+qG/3W+7l1NZTPnP5zcjBgHqK5Zmtqu0Jw== X-OriginatorOrg: cornell.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 16d5d3ad-db27-468d-96cb-08d7d4d1fe0a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2020 17:44:27.3353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jz1eBVqwf1TcfxV1a3VWajSzgpqOBHrmoe0R4ZwrQOluGcyWLEFXzKoOwdXVce6PbCpOqYdDkzWjENTbu4q+hg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB5403 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Ken Brown via Cygwin Reply-To: Ken Brown Cc: "'cygwin'" Errors-To: cygwin-bounces AT cygwin DOT com Sender: "Cygwin" --------------3490EC22AEDD2AA7601603DD Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable On 3/28/2020 10:19 PM, Ken Brown via Cygwin wrote: > On 3/28/2020 11:43 AM, Ken Brown via Cygwin wrote: >> On 3/28/2020 8:10 AM, sten DOT kristian DOT ivarsson AT gmail DOT com wrote: >>>> On 3/27/2020 10:53 AM, sten DOT kristian DOT ivarsson AT gmail DOT com wrote: >>>>>> On 3/26/2020 7:19 PM, Ken Brown via Cygwin wrote: >>>>>>> On 3/26/2020 6:39 PM, Ken Brown via Cygwin wrote: >>>>>>>> On 3/26/2020 6:01 PM, sten DOT kristian DOT ivarsson AT gmail DOT com wrote: >>>>>>>>> The ENIXIO occurs when parallel child-processes simultaneously >>>>>>>>> using O_NONBLOCK opening the descriptor. >>>>>>>> >>>>>>>> This is consistent with my guess that the error is generated by >>>>>>>> fhandler_fifo::wait.=A0 I have a feeling that read_ready should = have >>>>>>>> been created as a manual-reset event, and that more care is need= ed >>>>>>>> to make sure it's set when it should be. >>>>>>>> >>>>>>>>> I could provide a code-snippet >>>>>>>>> to reproduce it if wanted ? >>>>>>>> >>>>>>>> Yes, please! >>>>>>> >>>>>>> That might not be necessary.=A0 If you're able to build the git r= epo >>>>>>> master branch, please try the attached patch. >>>>> >>>>>> Here's a better patch. >>>>> >>>>> >>>>> I finally succeeded to build latest master (make is not my favourit= e >>>>> tool) and added the patch, but still no success in my little >>>>> test-program (see >>>>> attachment) when creating a write-file-descriptor with O_NONBLOCK >>> >>>> Your test program fails for me on Linux too.=A0 Here's the output fr= om one >>> run: >>> >>> You're right. That was extremely careless of me to not test this in L= inux >>> first :-) >> >> No problem. >> >>> I can assure that we have a use case that works on Linux but not in C= ygwin, >>> but it seems like I failed to narrow it down in the wrong way >>> >>> I'll try to rearrange my code (that works in Linux) to mimic our appl= ication >>> but in a simple way (I'll be back) >> >> OK, I'll be waiting for you.=A0 BTW, if it's not too hard to write you= r test=20 >> case in plain C, or at least less modern C++, that would simplify thin= gs for=20 >> me.=A0 For example, your pipe.cpp failed to compile on one Linux machi= ne I=20 >> wanted to test it on, presumably because that machine had an older C++= compiler. >=20 > Never mind.=A0 I was able to reproduce the problem and find the cause.=A0= What=20 > happens is that when the first subprocess exits, fhandler_fifo::close r= esets=20 > read_ready.=A0 That causes the second and subsequent subprocesses to th= ink that=20 > there's no reader open, so their attempts to open a writer with O_NONBL= OCK fail=20 > with ENXIO. >=20 > I should be able to fix this tomorrow. I've pushed what I think is a fix to the topic/fifo branch. I tested it = with=20 the attached program, which is a variant of the test case you sent last w= eek.=20 Please test it in your use case. Note: If you've previously pulled the topic/fifo branch, then you will pr= obably=20 get a lot of conflicts when you pull again, because I did a forced push a= few=20 days ago. If that happens, just do git reset --hard origin/topic/fifo It turned out that the fix required some of the ideas that I've been work= ing on=20 in connection with allowing multiple readers. Even though the code allow= s a=20 FIFO to be *explicitly* opened for reading only once, there can still be = several=20 open file descriptors for readers because of dup and fork. The existing = code on=20 git master doesn't handle those situations properly. The code on topic/fifo doesn't completely fix that yet, but I think it sh= ould=20 work under the following assumptions: 1. The FIFO is opened only once for reading. 2. The file descriptor obtained from this is the only one on which a read= is=20 attempted. I'm working on removing both of these restrictions. Ken --------------3490EC22AEDD2AA7601603DD Content-Type: text/plain; charset=UTF-8; name="fifo_fork_nonblocking_writers.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fifo_fork_nonblocking_writers.c" /* Adapted from https://sourceware.org/pipermail/cygwin/2020-March/244219.html */ #include #include #include #include #include #include #include #include #define FIFO "/tmp/myfifo" #define nsubproc 5 #define nmessages 4 #define pid_len 4 int error (const int n, const char *name) { fprintf (stderr, "\n%d\t%s:\t%d\t%s\n", getpid (), name, n, strerror (n)); return n; } int main () { if (mkfifo (FIFO, S_IRUSR | S_IWUSR | S_IWGRP) < 0 && errno != EEXIST) return error (errno, "mkfifo"); int rfd = open (FIFO, O_RDWR); if (rfd < 0) return error (errno, "open reader"); for (int i = 0; i < nsubproc; i++) { pid_t pid = fork (); if (pid < 0) return error (errno, "fork"); if (pid == 0) { printf ("child %d\n", getpid ()); for (int j = 0; j < nmessages; j++) { char buf[pid_len + 2]; /* +1 for newline, +1 for nul */ int wfd = open (FIFO, O_WRONLY | O_NONBLOCK); if (wfd < 0) _exit (error (errno, "open writer")); sprintf (buf, "%d\n", getpid ()); ssize_t nwritten = write (wfd, buf, strlen (buf)); if (nwritten < 0) error (errno, "write"); /* printf ("i = %d, j = %d, nwritten = %zd\n", i, j, nwritten); */ close (wfd); } _exit (0); } } printf ("parent\n"); char buf[pid_len + 2]; for (int i = 0; i < nsubproc; i++) for (int j = 0; j < nmessages; j++) { if (read (rfd, buf, nsubproc) < 0) error (errno, "read"); buf[pid_len + 1] = '\0'; printf ("%s", buf); } close (rfd); } --------------3490EC22AEDD2AA7601603DD Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple --------------3490EC22AEDD2AA7601603DD--