Homec4science

Formalize and centralize signal handling in libphutil scripts

Authored by epriestley <git@epriestley.com> on Sep 7 2016, 02:54.

Description

Formalize and centralize signal handling in libphutil scripts

Summary:
Ref T11592. By default, when PHP receives a SIGTERM, it just exits without running destructors.

This makes it difficult for us to release locks, free resources, terminate subprocesses, etc. We already fix this behavior in the daemon wrapper, but I want to extend this to all libphutil scripts so that everything terminates subprocesses correctly. Since pcntl_signal() can only accept one signal handler, that means we need to centralize signal handling.

This creates a centralized signal router and some formal signal handlers, and always installs basic routing behavior for SIGHUP (route, plus dump backtraces) and SIGTERM (exit, but run destructors).

Test Plan:
Used this test script:

<?php

require_once '../libphutil/scripts/__init_script__.php';

echo getmypid()."\n";

$future = new ExecFuture('sleep 240');
$future->resolve();
  • Sent it SIGTERM.
    • Before patch: sleep subprocess still alive.
    • After patch: sleep subprocess killed.
  • Sent it SIGHUP.
    • Verified it dumped a trace properly.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11592

Differential Revision: https://secure.phabricator.com/D16504

Details

Committed
epriestley <git@epriestley.com>Sep 7 2016, 03:24
Pushed
aubortMar 17 2017, 12:03
Parents
rPHUb00eff539ee7: Add Slack authentication adapter
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHUe94f6e738e2d: Formalize and centralize signal handling in libphutil scripts (authored by epriestley <git@epriestley.com>).Sep 7 2016, 03:24