Sv: Sv: Sv: Named pipes and multiple writers

Ken Brown kbrown@cornell.edu
Fri Mar 27 23:00:08 GMT 2020


On 3/27/2020 6:56 PM, Ken Brown via Cygwin wrote:
> On 3/27/2020 10:53 AM, sten.kristian.ivarsson@gmail.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.kristian.ivarsson@gmail.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.  I have a feeling that read_ready should have
>>>>> been created as a manual-reset event, and that more care is needed 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.  If you're able to build the git repo
>>>> master branch, please try the attached patch.
>>
>>> Here's a better patch.
>>
>>
>> I finally succeeded to build latest master (make is not my favourite 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.  Here's the output from one run:
> 
> child 657
> 657     error:  6       No such device or address
> child 658
> child 659
> 658659  error:  child 660
> parent
> child 661
>          error:  66606661 661 661
>                  error:          661
> No such device or address6No such device or address
> 
> No such device or address
> 
> [I then killed it with control-C; the parent was blocked trying to open the FIFO.]
> 
> There's a race condition in your code.  The parent is trying to open the FIFO 
> for reading (without O_NONBLOCK) while the child is trying to open it for 
> writing (with O_NONBLOCK).  The parent is blocked waiting for the child, and the 
> child's open fails with ENXIO; see
> 
>    https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html#tag_16_357
> 
> I think you need to rearrange things so that the FIFO is open for reading before 
> you try a nonblocking open for writing.

For example, you could open it with O_RDWR instead of O_RDONLY.


More information about the Cygwin mailing list