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

Re: [PATCH v6 13/13] read-cache: make sure file handles are not inherited by child processes

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 29, 2016, 19:45 UTC
Message-ID
<xmqq37lnbbpk.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<4D9E5AED-7003-4707-8791-1C25432DB558@gmail.com>
Lars Schneider <larsxschneider@gmail.com> writes:
> I see. Thanks for the explanation.

I expect the updated log message to explain the issue correctly then.

Show 10 quoted lines
>> And even on POSIX systems, if you are doing a long-running helper
>> any open file descriptor in the parent process when the long-running
>> helper is spawned will become leaked fd.  CLOEXEC is a possible
>> solution (but not necessarily the only or the best one) to the fd
>> leak in this case.
>> 
>> How much does the code that spawns these long-running helpers know
>> about the file descriptors that happen to be open?
>
> Nothing really.
OK.
Show 8 quoted lines
>> The parent is
>> very likely to have pack windows open into .pack files and they need
>> to be closed on the child side after fork(2) starts the child
>> process but before execve(2) runs the helper, if we want to avoid
>> file descriptor leaks.
>
> I think I understand what you are saying. However, during my tests
> .pack file fd's were never a problem.

I do not expect during the lifetime of your long-running helper anybody would try to unlink an existing packfile, so it is unlikely that "cannot unlink an open file on Windows" issue to come up. And the cross-platform problem I pointed out is a fd leak; leaks would not show up until you run out of the resource, just like you wouldn't notice small memory leak here and there UNLESS you actively look for them. I would be surprised if your "tests" found anything.

> How would I find the open .pack file fd's?  Should I go through
> /proc/PID/fd? Why is this no problem for other longer running
> commands such as the git-credential-cache--daemon or git-daemon?

Nobody said this is "no problem for others". While discussing the patch that started this thread, we noticed that any open file descriptor the main process has when the long-running clean/smudge helper is spawned _is_ a problem. Other helpers may share the same problem, and if they do, that is all the more reason that fixing the file descriptor leak is a good thing.

The primary thing I was wondering was if we should open the window into packfiles with CLOEXEC, just like we recently started opening the tempfiles and lockfiles with the flag. The reason why I asked if the site that spawns (i.e. run_command API) has an easy access to the list of file descriptors that we opened ONLY for ourselves is because that would make it possible to consider an alternative approach close them before execve(2) in run_commands API. That would save us from having to sprinkle existing calls to open(2) with CLOEXEC. But if that is not the case, opening them with CLOEXEC is a much better solution than going outside the program to "find" them in non-portable ways.

Thanks.
Previous: Lars SchneiderNext: Lars Schneider
Message 50 of 66 in “Git filter protocol”
  1. 00/13 Git filter protocollarsxschneider@gmail.com, Aug 25, 2016
  2. 10/13 convert: generate large test files only oncelarsxschneider@gmail.com, Aug 25, 2016
  3. Stefan BellerAug 25, 2016
  4. Lars SchneiderAug 25, 2016
  5. Junio C HamanoAug 29, 2016
  6. Lars SchneiderAug 30, 2016
  7. Junio C HamanoAug 30, 2016
  8. Junio C HamanoAug 29, 2016
  9. Lars SchneiderAug 30, 2016
  10. Jeff KingAug 30, 2016
  11. 06/13 pkt-line: add functions to read/write flush terminated packet streamslarsxschneider@gmail.com, Aug 25, 2016
  12. Stefan BellerAug 25, 2016
  13. Junio C HamanoAug 25, 2016
  14. Jacob KellerAug 26, 2016
  15. Stefan BellerAug 26, 2016
  16. Jeff KingAug 26, 2016
  17. Junio C HamanoAug 26, 2016
  18. Lars SchneiderAug 25, 2016
  19. Junio C HamanoAug 25, 2016
  20. Lars SchneiderAug 26, 2016
  21. Junio C HamanoAug 26, 2016
  22. Lars SchneiderAug 29, 2016
  23. 01/13 pkt-line: rename packet_write() to packet_write_fmt()larsxschneider@gmail.com, Aug 25, 2016
  24. 03/13 pkt-line: add packet_write_fmt_gently()larsxschneider@gmail.com, Aug 25, 2016
  25. Stefan BellerAug 25, 2016
  26. Lars SchneiderAug 25, 2016
  27. Junio C HamanoAug 25, 2016
  28. Lars SchneiderAug 26, 2016
  29. Junio C HamanoAug 26, 2016
  30. Jeff KingAug 26, 2016
  31. 11/13 convert: make apply_filter() adhere to standard Git error handlinglarsxschneider@gmail.com, Aug 25, 2016
  32. 12/13 convert: add filter.<driver>.process optionlarsxschneider@gmail.com, Aug 25, 2016
  33. Junio C HamanoAug 29, 2016
  34. Lars SchneiderAug 30, 2016
  35. Junio C HamanoAug 30, 2016
  36. Lars SchneiderAug 30, 2016
  37. Junio C HamanoAug 30, 2016
  38. Torsten BögershausenAug 31, 2016
  39. Jakub NarębskiAug 31, 2016
  40. Jakub NarębskiAug 30, 2016
  41. Lars SchneiderSep 5, 2016
  42. 05/13 pkt-line: add packet_write_gently()larsxschneider@gmail.com, Aug 25, 2016
  43. Junio C HamanoAug 25, 2016
  44. Lars SchneiderAug 26, 2016
  45. Junio C HamanoAug 26, 2016
  46. Lars SchneiderAug 29, 2016
  47. 13/13 read-cache: make sure file handles are not inherited by child processeslarsxschneider@gmail.com, Aug 25, 2016
  48. Junio C HamanoAug 29, 2016
  49. Lars SchneiderAug 29, 2016
  50. Junio C HamanoAug 29, 2016
  51. Lars SchneiderAug 30, 2016
  52. Torsten BögershausenAug 30, 2016
  53. Junio C HamanoSep 1, 2016
  54. 02/13 pkt-line: extract set_packet_header()larsxschneider@gmail.com, Aug 25, 2016
  55. 09/13 convert: modernize testslarsxschneider@gmail.com, Aug 25, 2016
  56. Junio C HamanoAug 26, 2016
  57. Lars SchneiderAug 29, 2016
  58. 08/13 convert: quote filter names in error messageslarsxschneider@gmail.com, Aug 25, 2016
  59. Junio C HamanoAug 26, 2016
  60. 04/13 pkt-line: add packet_flush_gently()larsxschneider@gmail.com, Aug 25, 2016
  61. 07/13 pack-protocol: fix maximum pkt-line sizelarsxschneider@gmail.com, Aug 25, 2016
  62. Stefan BellerAug 25, 2016
  63. Lars SchneiderAug 25, 2016
  64. Junio C HamanoAug 26, 2016
  65. Lars SchneiderAug 29, 2016
  66. Junio C HamanoAug 29, 2016

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.