Skip to content

gvfs-helper-client: clean up server process #756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions gvfs-helper-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,36 @@ static void gh_client__choose_odb(void)
}
}

/*
* Custom exit handler for the `gvfs-helper` subprocesses.
*
* These helper subprocesses will keep waiting for input until they are
* stopped. The default `subprocess_exit_handler()` will instead wait for
* the subprocess to exit, which is not what we want: In case of a fatal
* error, the Git process will exit and the `gvfs-helper` subprocesses will
* need to be stopped explicitly.
*
* The default behavior of `cleanup_children()` does, however, terminate
* the process after calling the `clean_on_exit_handler`. So that's exactly
* what we do here: reproduce the exact same code as
* `subprocess_exit_handler()` modulo waiting for the process that won't
* ever terminate on its own.
*/
static void gh_client__subprocess_exit_handler(struct child_process *process)
{
sigchain_push(SIGPIPE, SIG_IGN);
/* Closing the pipe signals the subprocess to initiate a shutdown. */
close(process->in);
close(process->out);
sigchain_pop(SIGPIPE);
/*
* In contrast to subprocess_exit_handler(), do _not_ wait for the
* process to finish on its own accord: It needs to be terminated via
* a signal, which is what `cleanup_children()` will do after this
* function returns.
*/
}

static struct gh_server__process *gh_client__find_long_running_process(
unsigned int cap_needed)
{
Expand Down Expand Up @@ -386,6 +416,9 @@ static struct gh_server__process *gh_client__find_long_running_process(
&entry->subprocess, 1,
&argv, gh_client__start_fn))
FREE_AND_NULL(entry);
else
entry->subprocess.process.clean_on_exit_handler =
gh_client__subprocess_exit_handler;
}

if (entry &&
Expand Down
4 changes: 4 additions & 0 deletions t/t9210-scalar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
)
'

test_expect_success 'fetch <non-existent> does not hang in gvfs-helper' '
test_must_fail git -C using-gvfs/src fetch origin does-not-exist
'

test_expect_success '`scalar clone --no-gvfs-protocol` skips gvfs/config' '
# the fake cache server requires fake authentication &&
git config --global core.askPass true &&
Expand Down
Loading