git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] receive-pack: interrupt pre-receive when client disconnects

From
Jiang Xin <worldhello.net@gmail.com>
Date
Jan 26, 2022, 07:17 UTC
Message-ID
<CANYiYbGRK0eshjUJoPH0yWT1tVLoerOMC6CY6tAMrwAh7T+y1g@mail.gmail.com>
In-Reply-To
<20220125095445.1796938-1-robin.jarry@6wind.com>
On Wed, Jan 26, 2022 at 12:09 AM Robin Jarry <robin.jarry@6wind.com> wrote:
Show 13 quoted lines
>
> When hitting ctrl-c on the client while a remote pre-receive hook is
> running, receive-pack is not killed by SIGPIPE because the signal is
> ignored. This is a side effect of commit ec7dbd145bd8 ("receive-pack:
> allow hooks to ignore its standard input stream").
>
> The pre-receive hook itself is not interrupted and does not receive any
> error since its stdout is a pipe which is read in an async thread and
> output back to the client socket in a side band channel.
>
> After the pre-receive has exited the SIGPIPE default handler is restored
> and if the hook did not report any error, objects are migrated from
> temporary to permanent storage.

We used to ignore the SIGPIPE signal when calling "pre-receive" hook, so we could tolerant a buggy "pre-receive" implementation which didn't consume all the input from "receive-pack". On the other side, "ctrl-c" from the client side will terminate "receive-pack", only if we do not ignore the SIGPIPE signal when running "pre-receive".

Wouldn't this be much simpler: add a new configuration variable "receive.loosePreReceiveImplementation", and only ignore SIGPIPE when "receive-pack" turns off the config variable?

Show 26 quoted lines
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index 9f4a0b816cf9..0f41fe8c6a85 100644
> @@ -522,10 +540,24 @@ static int copy_to_sideband(int in, int out, void *arg)
>                  * Either we're not looking for a NUL signal, or we didn't see
>                  * it yet; just pass along the data.
>                  */
> -               send_sideband(1, 2, data, sz, use_sideband);
> +               if (proc && proc->pid > 0) {
> +                       if (send_sideband2(1, 2, data, sz, use_sideband) < 0)
> +                               goto error;
> +               } else
> +                       send_sideband(1, 2, data, sz, use_sideband);
>         }
>         close(in);
>         return 0;
> +error:
> +       close(in);
> +       if (proc && proc->pid > 0) {
> +               /*
> +                * SIGPIPE would be more relevant but we want to make sure that
> +                * the hook does not ignore the signal.
> +                */
> +               kill(proc->pid, SIGKILL);
> +       }
> +       return -1;
>  }

Kill the "pre-receive" process, so the calling of "finish_command(&proc)" at the end of "run_and_feed_hook()" will terminate "receive-pack".

Show 15 quoted lines
> diff --git a/sideband.c b/sideband.c
> index 85bddfdcd4f5..27f8d653eb24 100644
> --- a/sideband.c
> +++ b/sideband.c
> +static int send_sideband_priv(int fd, int band, const char *data, ssize_t sz,
> +                             int packet_max, int ignore_errors)
>  {
>         const char *p = data;
>
> @@ -265,13 +279,24 @@ void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_ma
>                 if (0 <= band) {
>                         xsnprintf(hdr, sizeof(hdr), "%04x", n + 5);
>                         hdr[4] = band;
> -                       write_or_die(fd, hdr, 5);
> +                       if (ignore_errors)
"ignore_errors" or "die_on_errors"?
> +                               write_or_die(fd, hdr, 5);
> +                       else if (write_in_full(fd, hdr, 5) < 0)
> +                               return -1;

-- Jiang Xin

Previous: Robin JarryNext: Robin Jarry
Message 2 of 20 in “receive-pack: interrupt pre-receive when client disconnects”
  1. receive-pack: interrupt pre-receive when client disconnectsRobin Jarry, Jan 25, 2022
  2. Jiang XinJan 26, 2022
  3. Robin JarryJan 26, 2022
  4. receive-pack: add option to interrupt pre-receive when client exitsRobin Jarry, Jan 26, 2022
  5. Jiang XinJan 27, 2022
  6. Robin JarryJan 27, 2022
  7. Junio C HamanoJan 27, 2022
  8. Robin JarryJan 27, 2022
  9. Junio C HamanoJan 27, 2022
  10. Robin JarryJan 27, 2022
  11. receive-pack: check if client is alive before completing the pushRobin Jarry, Jan 27, 2022
  12. Junio C HamanoJan 28, 2022
  13. Robin JarryJan 28, 2022
  14. Junio C HamanoJan 28, 2022
  15. Robin JarryJan 28, 2022
  16. receive-pack: check if client is alive before completing the pushRobin Jarry, Jan 28, 2022
  17. Ævar Arnfjörð BjarmasonFeb 4, 2022
  18. Junio C HamanoFeb 4, 2022
  19. Robin JarryFeb 7, 2022
  20. Junio C HamanoJan 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.