@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Install a SIGTERM handler in ssh-connect

Summary:
Ref T10547. This has been around for a while but I was never able to reproduce it. I caught a repro case in the cluster recently and I think this is the right fix.

We tell Subversion to run `ssh-connect` instead of `ssh` so we can provide options and credentials, by using `SVN_SSH` in the environment. Subversion will sometimes kill the SSH tunnel subprocess aggressively with SIGTERM -- as of writing, you can search for `SIGTERM` in `make_tunnel()` here:

http://svn.apache.org/repos/asf/subversion/trunk/subversion/libsvn_ra_svn/client.c

By default, when a PHP process gets SIGTERM it just exits immediately, without running destructors or shutdown functions. Since destructors/shutdown functions don't run, `TempFile` doesn't get a chance to remove the file.

I don't have a clear picture of //when// Subversion sends SIGTERM to the child process. I can't really get this to trigger locally via `svn`, although I was able to get it to trigger explicitly. So I'm only about 95% sure this fixes it, but it seems likely.

Test Plan:
Locally, I couldn't get this to reproduce "normally" even knowing the cause (maybe Subversion doesn't do the SIGTERM stuff on OSX?) but I was able to get it to reproduce reliabily by adding `posix_kill(getmypid(), SIGTERM);` to the body of the script.

With that added, running the script with `PHABRICATOR_CREDENTIAL=PHID-CDTL-...` in the environment reliably left straggler temporary files.

Adding `declare()` and a signal handler fixed this: the script now runs the `TempFile` destructor and longer leaves the stragglers around.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10547

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

+15
+15
scripts/ssh/ssh-connect.php
··· 4 4 // This is a wrapper script for Git, Mercurial, and Subversion. It primarily 5 5 // serves to inject "-o StrictHostKeyChecking=no" into the SSH arguments. 6 6 7 + // In some cases, Subversion sends us SIGTERM. If we don't catch the signal and 8 + // react to it, we won't run object destructors by default and thus won't clean 9 + // up temporary files. Declare ticks so we can install a signal handler. 10 + declare(ticks=1); 11 + 7 12 $root = dirname(dirname(dirname(__FILE__))); 8 13 require_once $root.'/scripts/__init_script__.php'; 9 14 ··· 20 25 ), 21 26 )); 22 27 $unconsumed_argv = $args->getUnconsumedArgumentVector(); 28 + 29 + if (function_exists('pcntl_signal')) { 30 + pcntl_signal(SIGTERM, 'ssh_connect_signal'); 31 + } 32 + 33 + function ssh_connect_signal($signo) { 34 + // This is just letting destructors fire. In particular, we want to clean 35 + // up any temporary files we wrote. See T10547. 36 + exit(128 + $signo); 37 + } 23 38 24 39 $pattern = array(); 25 40 $arguments = array();