Skip to content
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

Improve the way GAP terminates subprocesses to avoid a race condition that could lead to unwanted warnings or even hangs #5804

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,11 @@ static Obj FuncSIGNAL_CHILD_IOSTREAM(Obj self, Obj stream, Obj sig)
static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
{
UInt pty = HashLockStreamIfAvailable(stream);
int status, retcode;

// Close down the child
int status;
kill(PtyIOStreams[pty].childPID, SIGTERM);
int retcode = close(PtyIOStreams[pty].ptyFD);
if (retcode)
Pr("Strange close return code %d\n", retcode, 0);

// GAP (or another library) might wait on this PID before
// we handle it. If that happens, waitpid will return -1.
retcode = waitpid(PtyIOStreams[pty].childPID, &status, WNOHANG);
Expand All @@ -1028,6 +1026,10 @@ static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
retcode = waitpid(PtyIOStreams[pty].childPID, &status, 0);
}

retcode = close(PtyIOStreams[pty].ptyFD);
if (retcode)
Pr("Strange close return code %d\n", retcode, 0);

PtyIOStreams[pty].inuse = 0;

FreeStream(pty);
Expand Down
Loading