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

Re: [PATCH v2] pipe_command(): mark stdin descriptor as non-blocking

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 9, 2022, 22:10 UTC
Message-ID
<4o5p308o-9r66-2853-qon0-r1464p2o83qn@tzk.qr>
In-Reply-To
<YvJbXJyaKz5QPYdz@coredump.intra.peff.net>
Hi Peff,
On Tue, 9 Aug 2022, Jeff King wrote:
Show 19 quoted lines
> On Mon, Aug 08, 2022 at 02:59:49PM +0200, Johannes Schindelin wrote:
>
> > On Tue, 2 Aug 2022, Jeff King wrote:
> >
> > > diff --git a/run-command.c b/run-command.c
> > > index 14f17830f5..ed99503b22 100644
> > > --- a/run-command.c
> > > +++ b/run-command.c
> > > @@ -1438,6 +1439,15 @@ int pipe_command(struct child_process *cmd,
> > >  		return -1;
> > >
> > >  	if (in) {
> > > +		if (enable_nonblock(cmd->in) < 0) {
> > > +			error_errno("unable to make pipe non-blocking");
> >
> > It might be a bit heavy-handed to error out in this case, as it usually
> > does not cause problems. At least that's what the fact suggests to me that
> > I personally never encountered the dead-lock myself, and neither do I
> > recall anybody piping more than two megabytes through `git checkout -p`.

Ugh, I think that my reasoning was flawed, as I somehow based it on the assumption that `enable_nonblock()` would return -1 on platforms without O_NONBLOCK. Even if I had read that you fall back to returning 0 on those platforms.

And only when reading your reply did it occur to me that this was a thinko on my part.

So I would like to retract my assessment that it is heavy-handed to error out in this case. It would have been if we had errored out on platforms without O_NONBLOCK support, but we don't.

Sorry for the noise, Dscho

Show 31 quoted lines
>
> That thought crossed my mind, as well, but I'm hesitant to leave a known
> bug in place that can cause a deadlock. It would be one thing if we
> could muddle through without nonblock in a slower way, but I don't think
> we can easily detect this situation after the fact.
>
> So maybe some options are:
>
>   - don't bother with O_NONBLOCK unless the size of the input is over N
>     bytes. The trouble there is that it's not clear what N should be.
>     It's fcntl(F_GETPIPE_SZ) on Linux, but that's not portable. We could
>     possibly come up with a conservative value if we had a ballpark for
>     pipe size on Windows. It feels a bit hacky, though.
>
>   - we could actually guess at a deadlock by putting a timeout on the
>     poll(). That would also catch hanging or slow filter processes. I
>     really hate putting clock-based limits on things, though, as it
>     means the tool behaves differently under load. And keep in mind this
>     is deep in the pipe_command() code. It happens to only trigger for
>     diff filters now, but it may be used in other spots (in fact it
>     already is, and it's only the size of current gpg payloads/responses
>     that means it doesn't happen to trigger).
>
> Stepping back, though, I think we should consider why we'd see an error
> here. I wouldn't expect it to ever fail on a system where O_NONBLOCK was
> supported. If we want to make it a silent noop on some platforms, then
> we can stick that into the enable_nonblock() function (which is what I
> did, but as René showed, that is probably not a good enough solution).
>
> -Peff
>
Previous: Jeff King
Message 44 of 44 in “pipe_command(): mark stdin descriptor as non-blocking”
  1. pipe_command(): mark stdin descriptor as non-blockingJeff King, Aug 2, 2022
  2. Junio C HamanoAug 2, 2022
  3. Jeff KingAug 2, 2022
  4. Junio C HamanoAug 2, 2022
  5. pipe_command(): mark stdin descriptor as non-blockingJeff King, Aug 3, 2022
  6. René ScharfeAug 3, 2022
  7. Jeff KingAug 3, 2022
  8. René ScharfeAug 3, 2022
  9. Jeff KingAug 5, 2022
  10. René ScharfeAug 5, 2022
  11. René ScharfeAug 7, 2022
  12. Jeff KingAug 7, 2022
  13. mingw: handle writes to non-blocking pipeRené Scharfe, Aug 10, 2022
  14. Johannes SchindelinAug 10, 2022
  15. Jeff KingAug 10, 2022
  16. René ScharfeAug 10, 2022
  17. Jeff KingAug 11, 2022
  18. René ScharfeAug 11, 2022
  19. Jeff KingAug 11, 2022
  20. René ScharfeAug 14, 2022
  21. Jeff KingAug 17, 2022
  22. 0/6 fix pipe_command() deadlockJeff King, Aug 17, 2022
  23. 1/6 compat: add function to enable nonblocking pipesJeff King, Aug 17, 2022
  24. Junio C HamanoAug 17, 2022
  25. Jeff KingAug 18, 2022
  26. 2/6 nonblock: support WindowsJeff King, Aug 17, 2022
  27. 3/6 git-compat-util: make MAX_IO_SIZE define globally availableJeff King, Aug 17, 2022
  28. 4/6 pipe_command(): avoid xwrite() for writing to pipeJeff King, Aug 17, 2022
  29. 5/6 pipe_command(): handle ENOSPC when writing to a pipeJeff King, Aug 17, 2022
  30. Junio C HamanoAug 17, 2022
  31. Jeff KingAug 18, 2022
  32. 6/6 pipe_command(): mark stdin descriptor as non-blockingJeff King, Aug 17, 2022
  33. Jeff KingAug 17, 2022
  34. René ScharfeAug 19, 2022
  35. Jeff KingAug 20, 2022
  36. René ScharfeAug 10, 2022
  37. Jeff KingAug 10, 2022
  38. René ScharfeAug 10, 2022
  39. Jeff KingAug 11, 2022
  40. René ScharfeAug 7, 2022
  41. Johannes SchindelinAug 8, 2022
  42. Johannes SchindelinAug 8, 2022
  43. Jeff KingAug 9, 2022
  44. Johannes SchindelinAug 9, 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.