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

proc: fix TestIssue1101 flake #3585

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions pkg/proc/native/proc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,23 @@ func trapWaitInternal(procgrp *processGroup, pid int, options trapWaitOptions) (
}
// do the same thing we do if a thread quit
if wpid == dbp.pid {
exitStatus := 0
if procgrp.numValid() == 1 {
// try to recover the real exit status using waitpid
for {
wpid2, status2, err := dbp.wait(-1, sys.WNOHANG)
if wpid2 <= 0 || err != nil {
break
}
if status2.Exited() {
exitStatus = status2.ExitStatus()
}
}

}
dbp.postExit()
if procgrp.numValid() == 0 {
return nil, proc.ErrProcessExited{Pid: wpid, Status: status.ExitStatus()}
return nil, proc.ErrProcessExited{Pid: wpid, Status: exitStatus}
}
continue
}
Expand Down Expand Up @@ -693,8 +707,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na
for {
th, err := trapWaitInternal(procgrp, -1, trapWaitNohang)
if err != nil {
p := procgrp.procForThread(th.ID)
return nil, exitGuard(p, procgrp, err)
return nil, exitGuard(procgrp.procs[0], procgrp, err)
}
if th == nil {
break
Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3690,7 +3690,7 @@ func TestIssue1101(t *testing.T) {
// Also it seems that sometimes on linux/386 we will not receive the
// exit status. This happens if the process exits at the same time as it
// receives a signal.
t.Fatalf("process exited status %d (expected 2)", pexit.Status)
t.Fatalf("process exited status %d (expected 2) (last command = %s) (%#v)", pexit.Status, lastCmd, pexit)
}
} else {
assertNoError(exitErr, t, lastCmd)
Expand Down