-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
popen module #1248
Comments
Closed
Totktonada
added a commit
to tarantool/tarantool
that referenced
this issue
May 18, 2020
killpg() on Mac OS may don't deliver a signal to a process: it seems that there is a race when a process is just forked. It means that popen_handle:close() may leave a process alive, when `opts.setsid` and `opts.group_signal` are set. There is simple reproducer, which does not leave alive `sleep 120` processes on Linux, but does it on Mac OS (within three-four runs in rows): | #include <signal.h> | #include <unistd.h> | #include <fcntl.h> | | int | main() | { | char *child_argv[] = { | "/bin/sh", | "-c", | "sleep 120", | NULL, | }; | pid_t pid; | int fd[2]; | pipe(fd); | fcntl(fd[0], F_SETFD, FD_CLOEXEC); | fcntl(fd[1], F_SETFD, FD_CLOEXEC); | | if ((pid = fork()) == 0) { | /* Child. */ | close(fd[0]); | setpgrp(); | for (int i = 0; i < 10; ++i) { | /* Proceed with killpg. */ | if (i == 5) | close(fd[1]); | if (fork() == 0) { | /* Child. */ | execve("/bin/sh", child_argv, NULL); | } | } | } else { | /* Parent. */ | close(fd[1]); | char c; | read(fd[0], &c, 1); | killpg(pid, SIGKILL); | } | return 0; | } Compile it (`cc test.c -o test`) and run several times: $ for i in $(seq 1 1000); do \ echo $i; \ ./test \ && ps -o pid,pgid,command -ax | grep [s]leep \ && break; \ done This is the reason why `sleep 120` process may be alive even when the whole test passes. test-run captures stdout and stderr of a 'core = app' test and waits EOF on them. If a child process inherit one of them or both, the fd is still open for writing and so EOF situation will not appear until `sleep 120` will exit. This commit doesn't try to overcome the root of the problem, but close stdout and stderr for the child process that may not be killed / exited in time. Aside of this, updated found Mac OS peculiars in API comments of C and Lua popen modules. Fixes #4938 @TarantoolBot document Title: popen: add note re group signaling on Mac OS Copyed from the popen_handle:signal() updated description: > Note: Mac OS may don't deliver a signal to a process in a group when > opts.setsid and opts.group_signal are set. It seems there is a race > here: when a process is just forked it may be not signaled. Copyed from the popen_handle:close() updated description: > Details about signaling: > > <...> > - There are peculiars in group signaling on Mac OS, > @see popen_handle:signal() for details. Follows up tarantool/doc#1248
kyukhin
pushed a commit
to tarantool/tarantool
that referenced
this issue
May 20, 2020
killpg() on Mac OS may don't deliver a signal to a process: it seems that there is a race when a process is just forked. It means that popen_handle:close() may leave a process alive, when `opts.setsid` and `opts.group_signal` are set. There is simple reproducer, which does not leave alive `sleep 120` processes on Linux, but does it on Mac OS (within three-four runs in rows): | #include <signal.h> | #include <unistd.h> | #include <fcntl.h> | | int | main() | { | char *child_argv[] = { | "/bin/sh", | "-c", | "sleep 120", | NULL, | }; | pid_t pid; | int fd[2]; | pipe(fd); | fcntl(fd[0], F_SETFD, FD_CLOEXEC); | fcntl(fd[1], F_SETFD, FD_CLOEXEC); | | if ((pid = fork()) == 0) { | /* Child. */ | close(fd[0]); | setpgrp(); | for (int i = 0; i < 10; ++i) { | /* Proceed with killpg. */ | if (i == 5) | close(fd[1]); | if (fork() == 0) { | /* Child. */ | execve("/bin/sh", child_argv, NULL); | } | } | } else { | /* Parent. */ | close(fd[1]); | char c; | read(fd[0], &c, 1); | killpg(pid, SIGKILL); | } | return 0; | } Compile it (`cc test.c -o test`) and run several times: $ for i in $(seq 1 1000); do \ echo $i; \ ./test \ && ps -o pid,pgid,command -ax | grep [s]leep \ && break; \ done This is the reason why `sleep 120` process may be alive even when the whole test passes. test-run captures stdout and stderr of a 'core = app' test and waits EOF on them. If a child process inherit one of them or both, the fd is still open for writing and so EOF situation will not appear until `sleep 120` will exit. This commit doesn't try to overcome the root of the problem, but close stdout and stderr for the child process that may not be killed / exited in time. Aside of this, updated found Mac OS peculiars in API comments of C and Lua popen modules. Fixes #4938 @TarantoolBot document Title: popen: add note re group signaling on Mac OS Copyed from the popen_handle:signal() updated description: > Note: Mac OS may don't deliver a signal to a process in a group when > opts.setsid and opts.group_signal are set. It seems there is a race > here: when a process is just forked it may be not signaled. Copyed from the popen_handle:close() updated description: > Details about signaling: > > <...> > - There are peculiars in group signaling on Mac OS, > @see popen_handle:signal() for details. Follows up tarantool/doc#1248
kyukhin
pushed a commit
to tarantool/tarantool
that referenced
this issue
May 20, 2020
killpg() on Mac OS may don't deliver a signal to a process: it seems that there is a race when a process is just forked. It means that popen_handle:close() may leave a process alive, when `opts.setsid` and `opts.group_signal` are set. There is simple reproducer, which does not leave alive `sleep 120` processes on Linux, but does it on Mac OS (within three-four runs in rows): | #include <signal.h> | #include <unistd.h> | #include <fcntl.h> | | int | main() | { | char *child_argv[] = { | "/bin/sh", | "-c", | "sleep 120", | NULL, | }; | pid_t pid; | int fd[2]; | pipe(fd); | fcntl(fd[0], F_SETFD, FD_CLOEXEC); | fcntl(fd[1], F_SETFD, FD_CLOEXEC); | | if ((pid = fork()) == 0) { | /* Child. */ | close(fd[0]); | setpgrp(); | for (int i = 0; i < 10; ++i) { | /* Proceed with killpg. */ | if (i == 5) | close(fd[1]); | if (fork() == 0) { | /* Child. */ | execve("/bin/sh", child_argv, NULL); | } | } | } else { | /* Parent. */ | close(fd[1]); | char c; | read(fd[0], &c, 1); | killpg(pid, SIGKILL); | } | return 0; | } Compile it (`cc test.c -o test`) and run several times: $ for i in $(seq 1 1000); do \ echo $i; \ ./test \ && ps -o pid,pgid,command -ax | grep [s]leep \ && break; \ done This is the reason why `sleep 120` process may be alive even when the whole test passes. test-run captures stdout and stderr of a 'core = app' test and waits EOF on them. If a child process inherit one of them or both, the fd is still open for writing and so EOF situation will not appear until `sleep 120` will exit. This commit doesn't try to overcome the root of the problem, but close stdout and stderr for the child process that may not be killed / exited in time. Aside of this, updated found Mac OS peculiars in API comments of C and Lua popen modules. Fixes #4938 @TarantoolBot document Title: popen: add note re group signaling on Mac OS Copyed from the popen_handle:signal() updated description: > Note: Mac OS may don't deliver a signal to a process in a group when > opts.setsid and opts.group_signal are set. It seems there is a race > here: when a process is just forked it may be not signaled. Copyed from the popen_handle:close() updated description: > Details about signaling: > > <...> > - There are peculiars in group signaling on Mac OS, > @see popen_handle:signal() for details. Follows up tarantool/doc#1248 (cherry picked from commit 0afba95)
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(cherry picked from commit 34c2789b48eadd36da742f7f761a998889e70544)
Requested by @Totktonada in tarantool/tarantool@6d1c5ff.
The text was updated successfully, but these errors were encountered: