Professional Web Applications Themes

fflush to pipe hangs when child at other end closes the pipe - AIX

My AIX 4.3.3 application calls popen(name, "w") to create a pipe to a the named child executable. All is well as long as the child stays active. But to test the situation when the child unexpectedly dies, I had the child exit after reading 5 lines of its standard input. After that, the parent process (that called popen) behaves as follows: All calls to fprintf() continue to return a positive value that indicates the number of bytes in the string I am sending to the client. It appears to happily buffer data in the pipe even though the other end ...

  1. #1

    Default fflush to pipe hangs when child at other end closes the pipe

    My AIX 4.3.3 application calls popen(name, "w") to create a pipe
    to a the named child executable. All is well as long as the
    child stays active.

    But to test the situation when the child unexpectedly dies, I
    had the child exit after reading 5 lines of its standard input.
    After that, the parent process (that called popen) behaves as
    follows:

    All calls to fprintf() continue to return a positive value
    that indicates the number of bytes in the string I am
    sending to the client. It appears to happily buffer data in
    the pipe even though the other end is closed.

    But a call to fflush() to flush the potentially buffered
    data hangs.

    Shouldn't fflush() return an error to indicate that the pipe has
    been broken when the child exited and caused its end of the pipe
    to be closed? And shouldn't fprintf() return with an error since
    the pipe is no longer usable?

    When the same scenario happens over a socket and the reader
    exits unexpectedly, the writer's calls to fprintf() and fflush()
    fail as expected and return -1 to indicate that failure.

    Is there something else about a pipe on AIX 4.3.3 that I need to
    check before calling fprintf() or fflush()?
    Brian Yoder Guest

  2. #2

    Default Re: fflush to pipe hangs when child at other end closes the pipe

    [email]beyoderisxinc.com[/email] (Brian Yoder) writes:
    > All calls to fprintf() continue to return a positive value
    > that indicates the number of bytes in the string I am
    > sending to the client. It appears to happily buffer data in
    > the pipe even though the other end is closed.
    As it should. After all, the only way fprintf() can now that all
    is not well is by performing the write(), but then it would loose
    the performance advantage of buffering.
    > But a call to fflush() to flush the potentially buffered
    > data hangs.
    Did you block SIGPIPE? In my test case, the parent dies with SIGPIPE
    after about 160 characters have been written to the pipe (over 20
    separate fprintf()s). If I make it catch or ignore SIGPIPE, fprintf
    eventually returns -1. I did not observe fflush() hang under any
    conditions. All on AIX4.3.3
    > When the same scenario happens over a socket and the reader
    > exits unexpectedly, the writer's calls to fprintf() and fflush()
    > fail as expected and return -1 to indicate that failure.
    Surely you are not calling fprintf()/fflush() on a socket?
    On fdopen()ed file stream perhaps? In which case, I expect the
    exact same behaviour (the one that I observed).

    Construct a simple test case which tes the behaviour.
    If it does, submit bug report to IBM (but chances are you'll find
    a bug in your program before you get your test case to te
    its behaviour).

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Paul Pluzhnikov Guest

  3. #3

    Default Re: fflush to pipe hangs when child at other end closes the pipe

    Brian Yoder wrote:
    > My AIX 4.3.3 application calls popen(name, "w") to create a pipe
    > to a the named child executable. All is well as long as the
    > child stays active.
    wild guess: another process (the parent or something else that the
    parent spawned) also has a descriptor open for the read side of that
    pipe, so when the child dies there is still a potential reader and the
    flush operation hangs waiting for that potential reader to read from the
    pipe and empty the kernel's buffer so that the write operation can complete)

    lsof is one of your best friends for checking out this theory

    Jeff Trawick Guest

Similar Threads

  1. [ANN] win32-pipe 0.0.1
    By Daniel Berger in forum Ruby
    Replies: 0
    Last Post: November 22nd, 07:19 AM
  2. [PHP] Pipe an email to PHP
    By Thomas Tremain in forum PHP Development
    Replies: 2
    Last Post: August 30th, 10:33 PM
  3. Pipe an email to PHP
    By Thomas Tremain in forum PHP Development
    Replies: 2
    Last Post: August 27th, 01:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139