Skip to content

Commit

Permalink
fix: process the final pipe input event before closing (#8)
Browse files Browse the repository at this point in the history
In the event that poll returned both POLLIN and POLLHUP in a single pass we
were mistakenly closing the file descriptor without processing that final
input. This was addressed by changing the condition for ending the loop.

Also expanded the midline-flush test to run 10 times because that's what
was most effective in demonstrating the problem.
  • Loading branch information
limeytexan authored Dec 18, 2024
1 parent 5b71242 commit 7d5f5c5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions t3.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ int main(int argc, char *argv[]) {
pfds[0].revents & POLLIN, pfds[0].revents & POLLPRI,
pfds[0].revents & POLLOUT, pfds[0].revents & POLLERR,
pfds[0].revents & POLLHUP, pfds[0].revents & POLLNVAL);
if ((pfds[0].revents & POLLIN) && !(pfds[0].revents & POLLHUP)) {
if (pfds[0].revents & POLLIN) {
_debug(2, "detected input on stdout_msg_pipe[0]");
struct payload *msg_payload = malloc(sizeof(struct payload));
if (read(stdout_msg_pipe[0], msg_payload, sizeof(struct payload)) >
Expand All @@ -659,7 +659,7 @@ int main(int argc, char *argv[]) {
num_open_fds--;
waitpid(stdout_worker, NULL, WNOHANG);
}
if ((pfds[1].revents & POLLIN) && !(pfds[1].revents & POLLHUP)) {
if (pfds[1].revents & POLLIN) {
_debug(2, "detected input on stderr_msg_pipe[0]");
struct payload *msg_payload = malloc(sizeof(struct payload));
if (read(stderr_msg_pipe[0], msg_payload, sizeof(struct payload)) >
Expand Down
2 changes: 1 addition & 1 deletion tests/midline-flush.args
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-- tests/midline-flush
-- sh -c 'for i in `seq 1 10`; do tests/midline-flush; done'
9 changes: 9 additions & 0 deletions tests/midline-flush.err
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
Hello, stderr! Goodbye, stderr!
18 changes: 18 additions & 0 deletions tests/midline-flush.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
Hello, stderr! Goodbye, stderr!
Hello, stdout! Goodbye, stdout!
9 changes: 9 additions & 0 deletions tests/midline-flush.out
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!
Hello, stdout! Goodbye, stdout!

0 comments on commit 7d5f5c5

Please sign in to comment.