Bug 213928 - Reapers don't receive SIGCHLD when inheriting zombies
Summary: Reapers don't receive SIGCHLD when inheriting zombies
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-31 00:49 UTC by Michael Zuo
Modified: 2017-03-09 17:37 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Zuo 2016-10-31 00:49:58 UTC
If a process acquires reaper status with procctl (or if it's init), then when one of its children exits, its children, including zombies, get reparented.

If a zombie gets reparented, the reaper receives no notification, so unless it's looping around a wait* for unspecified children, the zombie won't get reaped until the reaper exits.

This doesn't seem to be a problem for init, which does indeed loop around waitpid(-1,0,0). However, it makes it hard for a correct program which acquires reaper status to do anything interesting, as such a program should not block on anything but a wait* call unless it can guarantee that none of its descendants will exit with zombies, as otherwise the system can accumulate zombies.
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-12-12 11:12:24 UTC
A commit references this bug:

Author: kib
Date: Mon Dec 12 11:11:50 UTC 2016
New revision: 309886
URL: https://svnweb.freebsd.org/changeset/base/309886

Log:
  When a zombie gets reparented due to the parent exit, send SIGCHLD to
  the reaper.

  The traditional reaper init(8) is aware of zombies silently reparented
  to it after the parents exit, it loops around waitpid(2) to collect
  them.  For other reapers, the silent reparenting is surprising and
  collecting zombies requires a thread blocking in waitpid(2) just for
  that purpose.  It seems that sending second SIGCHLD is a better
  workaround than forcing all reapers to obey the setup.

  Reported by:	 Michael Zuo <muh.muhten@gmail.com>, jilles
  PR:	213928
  Reviewed by:	jilles (previous version)
  Sponsored by:	The FreeBSD Foundation
  MFC after:	2 weeks

Changes:
  head/sys/kern/kern_exit.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-12-12 22:52:05 UTC
A commit references this bug:

Author: jilles
Date: Mon Dec 12 22:51:29 UTC 2016
New revision: 309957
URL: https://svnweb.freebsd.org/changeset/base/309957

Log:
  Add tests for reaper receiving SIGCHLD (r309886).

  PR:		213928
  MFC after:	2 weeks

Changes:
  head/tests/sys/kern/reaper.c
Comment 3 Jilles Tjoelker freebsd_committer freebsd_triage 2016-12-14 16:46:37 UTC
Fixed in head, MFC pending.
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-12-26 14:39:29 UTC
A commit references this bug:

Author: jilles
Date: Mon Dec 26 14:39:05 UTC 2016
New revision: 310601
URL: https://svnweb.freebsd.org/changeset/base/310601

Log:
  MFC r309957: Add tests for reaper receiving SIGCHLD (r309886).

  PR:		213928

Changes:
_U  stable/11/
  stable/11/tests/sys/kern/reaper.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-12-26 17:27:03 UTC
A commit references this bug:

Author: jilles
Date: Mon Dec 26 17:26:25 UTC 2016
New revision: 310610
URL: https://svnweb.freebsd.org/changeset/base/310610

Log:
  MFC r309957: Add tests for reaper receiving SIGCHLD (r309886).

  PR:		213928

Changes:
_U  stable/10/
  stable/10/tests/sys/kern/reaper.c
Comment 6 Jilles Tjoelker freebsd_committer freebsd_triage 2016-12-26 17:47:22 UTC
Fixed in head, stable/11 and stable/10.
Comment 7 Bryan Drewery freebsd_committer freebsd_triage 2017-03-09 17:37:08 UTC
This has an apparent race and potential fix at https://lists.freebsd.org/pipermail/freebsd-current/2017-March/065123.html