Home GnuPG

Formalize and centralize signal handling in libphutil scripts
e94f6e738e2dUnpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

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

Provenance
epriestley <git@epriestley.com>Authored on Sep 7 2016, 2:54 AM
Parents
rPHUTILb00eff539ee7: Add Slack authentication adapter
Branches
Unknown
Tags
Unknown

Event Timeline

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