[Bug 248440] kevent not returning full pipes registered with EVFILT_WRITE when on read end closure

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Aug 2 23:20:03 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=248440

            Bug ID: 248440
           Summary: kevent not returning full pipes registered with
                    EVFILT_WRITE when on read end closure
           Product: Base System
           Version: 12.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs at FreeBSD.org
          Reporter: larkinconr at gmail.com
 Attachment #216970 text/plain
         mime type:

Created attachment 216970
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=216970&action=edit
test program to reproduce bug via filling/monitoring stdout

When using kevent to monitor the write end of a pipe for writability via
EVFILT_WRITE, if the pipe is full when the read end is closed, an event is not
returned. I would expect an event with EV_EOF set to be returned. Note that
this does not seem to reproduce with sockets or named pipes (fifos), those
return an event with EV_EOF set just fine in this situation.

I'm attaching a sample program that verifies stdout is a pipe and then attempts
to fill  it with data, then waits for an event with EVFILT_WRITE for stdout. If
you pipe this to  some program that doesn't read stdin, for instance sleep(1),
the pipeline hangs forever. Notably, if you instead redirect its output to a
named pipe and have sleep "read" the named pipe with shell redirection, the
program *does* receive an event for stdout with EV_EOF set once sleep exits.

I originally detected this with a test case that creates a pipe via pipe(2) in
process, so testing with socketpair(2) was convenient, but it used threads and
other infrastructure etc so I wrote a new test program. But I just want to
mention that because it would seem to exclude some weird interaction with my
shell etc.

Example test case using the attached kqwrite.c:

$ ./kqwrite | /bin/sleep 1 # hangs forever
^C
$ mkfifo dummy; /bin/sleep 1 < dummy &; ./kqwrite > dummy # returns EV_EOF:
[1] 1734
kevent returned 1
        1 -2 32768 0 0 0x0
[1]  + done       /bin/sleep 1 < dummy

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list