diff --git a/proc/proc_linux.go b/proc/proc_linux.go index 3585b440bf96e524b3c8318a2660a29c9a696eab..504ea931ce26453a06429941396b88e4e9c233d0 100644 --- a/proc/proc_linux.go +++ b/proc/proc_linux.go @@ -116,6 +116,9 @@ func (dbp *Process) addThread(tid int, attach bool) (*Thread, error) { return nil, fmt.Errorf("error while waiting after adding thread: %d %s", tid, err) } dbp.execPtraceFunc(func() { err = syscall.PtraceSetOptions(tid, syscall.PTRACE_O_TRACECLONE) }) + if err == syscall.ESRCH { + return nil, err + } if err != nil { return nil, fmt.Errorf("could not set options for new traced thread %d %s", tid, err) } @@ -265,9 +268,18 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) { } th, err = dbp.addThread(int(cloned), false) if err != nil { + if err == sys.ESRCH { + // thread died while we were adding it + continue + } return nil, err } if err = th.Continue(); err != nil { + if err == sys.ESRCH { + // thread died while we were adding it + delete(dbp.Threads, th.Id) + continue + } return nil, fmt.Errorf("could not continue new thread %d %s", cloned, err) } if err = dbp.Threads[int(wpid)].Continue(); err != nil { diff --git a/service/test/integration_test.go b/service/test/integration_test.go index 3814560f12cb93569e03baada890f4f63025f6be..bd9901e1b9f03c1de2a0fb5d7aea380d7ab8a936 100644 --- a/service/test/integration_test.go +++ b/service/test/integration_test.go @@ -83,7 +83,7 @@ func TestRestart_afterExit(t *testing.T) { } state = <-c.Continue() if !state.Exited { - t.Fatal("expected restarted process to have exited") + t.Fatalf("expected restarted process to have exited %v", state) } }) }