Bug 237657 - sys.kern.pdeathsig.signal_delivered_ptrace timing out periodically
Summary: sys.kern.pdeathsig.signal_delivered_ptrace timing out periodically
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: tests (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-29 19:52 UTC by Enji Cooper
Modified: 2019-08-26 14:39 UTC (History)
3 users (show)

See Also:


Attachments
Wait for the process C termination or stop, in the later case detach. (439 bytes, patch)
2019-08-11 11:25 UTC, Konstantin Belousov
no flags Details | Diff
Fix two races in the ptrace process, one at attach, another at detach. (1.39 KB, patch)
2019-08-16 09:05 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer freebsd_triage 2019-04-29 19:52:46 UTC
It seems that the test case is timing out periodically on i386. Example: https://ci.freebsd.org/job/FreeBSD-head-i386-test/5228/testReport/junit/sys.kern/pdeathsig/signal_delivered_ptrace/.
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2019-08-11 11:23:13 UTC
At least one issue I noted is that ptrace(PT_DETACH) is called without the target process C being stopped.  This results in failure of detaching, i.e. the the debugger process D still has C attached, and then D exits.  If D exits before C executes its actions, C is killed because its debugger was killed.  Then, the wait for a pipe read in the process A becomes infinite, since the write end of the pipe exists in the process A as well.

Try the patch attached and report if it helped.
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2019-08-11 11:25:09 UTC
Created attachment 206439 [details]
Wait for the process C termination or stop, in the later case detach.
Comment 4 Li-Wen Hsu freebsd_committer freebsd_triage 2019-08-12 14:59:40 UTC
> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=206439

I have tested this patch but it still timed out sometimes.

Run this case in an infinite loop it usually failed because of timeout in 5 mins.

Is there any other information we can provide while running this?
Comment 5 Konstantin Belousov freebsd_committer freebsd_triage 2019-08-12 15:06:02 UTC
(In reply to Li-Wen Hsu from comment #4)
I need the ktrace -di/kdump of the failed run.
Comment 6 Li-Wen Hsu freebsd_committer freebsd_triage 2019-08-15 19:21:18 UTC
(In reply to Konstantin Belousov from comment #5)
Please check if these are useful: https://people.freebsd.org/~lwhsu/bug237657/
Comment 7 Konstantin Belousov freebsd_committer freebsd_triage 2019-08-16 09:05:10 UTC
Created attachment 206610 [details]
Fix two races in the ptrace process, one at attach, another at detach.

I see one more race, now B might exit before C ever set PROC_PDEATHSIG_CTL.

Try the updated patch.
Comment 8 Li-Wen Hsu freebsd_committer freebsd_triage 2019-08-19 08:57:29 UTC
With new patch this has been running in a while loop for 8 hours without error.  I think it is fine.
Comment 9 commit-hook freebsd_committer freebsd_triage 2019-08-19 09:29:57 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 19 09:29:27 UTC 2019
New revision: 351210
URL: https://svnweb.freebsd.org/changeset/base/351210

Log:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix debugger detach

  ptrace(PT_DETACH) requires stopped debuggee, otherwise it fails.  When
  the call fails, the C process is left as debuggee of the process D,
  and might be killed too early if process D exits occurs fast enough.

  Since pipes are not closed in the forked children, this resulted in
  the test hanging, since no write occured from C to wake A.

  PR:	237657
  Reported and tested by:	lwhsu
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Changes:
  head/tests/sys/kern/pdeathsig.c
Comment 10 commit-hook freebsd_committer freebsd_triage 2019-08-19 09:33:59 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 19 09:33:09 UTC 2019
New revision: 351211
URL: https://svnweb.freebsd.org/changeset/base/351211

Log:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix startup.

  Inform D that C executed procctl(PROC_PDEATHSIG_CTL).  Otherwise D
  might allow B to exit before C is set up to receive a signal on the
  parent exit.  In this case, C waits forever for the signal and test
  hangs.

  PR:	237657
  Reported and tested by:	lwhsu
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Changes:
  head/tests/sys/kern/pdeathsig.c
Comment 11 commit-hook freebsd_committer freebsd_triage 2019-08-26 08:06:44 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 26 08:06:19 UTC 2019
New revision: 351503
URL: https://svnweb.freebsd.org/changeset/base/351503

Log:
  MFC r351210:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix debugger detach

  PR:	237657

Changes:
_U  stable/12/
  stable/12/tests/sys/kern/pdeathsig.c
Comment 12 commit-hook freebsd_committer freebsd_triage 2019-08-26 08:07:46 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 26 08:07:10 UTC 2019
New revision: 351504
URL: https://svnweb.freebsd.org/changeset/base/351504

Log:
  MFC r351211:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix startup.

  PR:	237657

Changes:
_U  stable/12/
  stable/12/tests/sys/kern/pdeathsig.c
Comment 13 commit-hook freebsd_committer freebsd_triage 2019-08-26 08:08:47 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 26 08:07:47 UTC 2019
New revision: 351505
URL: https://svnweb.freebsd.org/changeset/base/351505

Log:
  MFC r351210:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix debugger detach

  PR:	237657

Changes:
_U  stable/11/
  stable/11/tests/sys/kern/pdeathsig.c
Comment 14 commit-hook freebsd_committer freebsd_triage 2019-08-26 08:08:49 UTC
A commit references this bug:

Author: kib
Date: Mon Aug 26 08:08:16 UTC 2019
New revision: 351506
URL: https://svnweb.freebsd.org/changeset/base/351506

Log:
  MFC r351211:
  sys.kern.pdeathsig.signal_delivered_ptrace: fix startup.

  PR:	237657

Changes:
_U  stable/11/
  stable/11/tests/sys/kern/pdeathsig.c