proc: bugfix: intermittent failures of TestRestart_afterExit

During process termination we seem to receive notifications of new
threads that die before we can add them, ignore them
This commit is contained in:
aarzilli 2015-09-26 21:36:13 +02:00
parent d81482c820
commit bba999b985
2 changed files with 13 additions and 1 deletions

@ -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 {

@ -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)
}
})
}