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

Re: [PATCH 05/16] fsmonitor--daemon: refactor cookie handling for readability

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Mar 21, 2022, 19:26 UTC
Message-ID
<49f2dbd2-b596-7378-ca65-ca5104121af5@jeffhostetler.com>
In-Reply-To
<xmqqo828s9xw.fsf@gitster.g>
On 3/14/22 1:47 PM, Junio C Hamano wrote:
Show 36 quoted lines
> Derrick Stolee <derrickstolee@github.com> writes:
> 
>> On 3/14/2022 4:00 AM, Ævar Arnfjörð Bjarmason wrote:
>>>
>>> On Fri, Mar 11 2022, Jeff Hostetler via GitGitGadget wrote:
>>
>>>> +	/*
>>>> +	 * Technically, close() and unlink() can fail, but we don't
>>>> +	 * care here.  We only created the file to trigger a watch
>>>> +	 * event from the FS to know that when we're up to date.
>>>> +	 */
>>>> +	close(fd);
>>>
>>> It still seems odd to explicitly want to ignore close() return values.
>>>
>>> I realize that we do in (too many) existing places, but why wouldn't we
>>> want to e.g. catch an I/O error here early?
>>
>> What exactly do you propose we do here if there is an I/O error
>> during close()?
> 
> We created the file to trigger a watch event, but now we have a
> reason to suspect that the wished-for watch event may not come.
> 
> We only did so to know that when we're up to date.  Now we may never
> know?  We may go without realizing we are already up to date a bit
> longer than the reality?
> 
> How much damage would it cause us to miss a watch event in this
> case?  Very little?  Is it a thing that sysadmins may care if we see
> too many of, but there is nothing the end user can immediately do
> about?  If it is, perhaps a trace2 event to report it (and other "we
> do not care here" syscalls that fail)?
> 
> 
> 

The open(... O_CREAT ...) succeeded, so we actually created a new file and expect a FS event for it. That FS event (when seen by the FS listener thread) will cause our condition to be signaled and allow this thread to wake up and respond to the client.

The odds of the close() failing on a plain file (after a successful open()) are very slim. And there's nothing that we can do about the failure anyway. (And we're not relying on an FS event from the close() succeeding, so it really doesn't matter.) Technically, it is possible that the daemon could run out of fd's if this close() fails often, so at some point the daemon might not be able to create new cookie files. But the daemon currently defaults to sending a trivial response to the client -- if this turns out to be a real issue, we could have the daemon restart or something, but I'm not going to worry about that right now.

The odds of a failure in unlink() is a little more interesting. This would mean that a stale cookie file would be left in the cookie directory (and waste a little disk space). But that is not likely either (for a plain file that we just created). Since we're not relying on the FS event for the unlink(), the failure here won't block the current thread either. Deleting stale cookie files is something that we could try to address in the future if it turns out to be a problem.

Jeff
Previous: Junio C HamanoNext: Jeff Hostetler via GitGitGadget
Message 8 of 32 in “Builtin FSMonitor Part 2.5”
  1. 00/16 Builtin FSMonitor Part 2.5Jeff Hostetler via GitGitGadget, Mar 11, 2022
  2. 01/16 t/test-lib: avoid using git on LHS of pipeJeff Hostetler via GitGitGadget, Mar 11, 2022
  3. Junio C HamanoMar 14, 2022
  4. 05/16 fsmonitor--daemon: refactor cookie handling for readabilityJeff Hostetler via GitGitGadget, Mar 11, 2022
  5. Ævar Arnfjörð BjarmasonMar 14, 2022
  6. Derrick StoleeMar 14, 2022
  7. Junio C HamanoMar 14, 2022
  8. Jeff HostetlerMar 21, 2022
  9. 02/16 update-index: convert advise() messages back to warning()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  10. Junio C HamanoMar 14, 2022
  11. Jeff HostetlerMar 21, 2022
  12. 10/16 t7527: delete unused verify_status() functionJeff Hostetler via GitGitGadget, Mar 11, 2022
  13. 11/16 fsmonitor-ipc: add _() to calls to die()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  14. 15/16 fsmonitor--daemon: add _() to calls to error()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  15. 12/16 compat/fsmonitor/fsm-listen-darwin: add _() to calls to error()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  16. 03/16 compat/fsmonitor/fsm-listen-darwin: split out GCC-specific declarationsJeff Hostetler via GitGitGadget, Mar 11, 2022
  17. 06/16 t/perf/p7519: use grep rather than egrep in testJeff Hostetler via GitGitGadget, Mar 11, 2022
  18. 07/16 t/perf/p7519: cleanup coding styleJeff Hostetler via GitGitGadget, Mar 11, 2022
  19. Ævar Arnfjörð BjarmasonMar 14, 2022
  20. 14/16 fsmonitor--daemon: add _() to calls to die()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  21. 09/16 t7527: fix && chaining in matrix_try()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  22. Junio C HamanoMar 14, 2022
  23. 08/16 t7527: add parameters to start_daemon to handle args and subshellJeff Hostetler via GitGitGadget, Mar 11, 2022
  24. Ævar Arnfjörð BjarmasonMar 14, 2022
  25. 04/16 t/helper/fsmonitor-client: cleanup call to parse_options()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  26. Ævar Arnfjörð BjarmasonMar 14, 2022
  27. 13/16 compat/fsmonitor/fsm-listen-win32: add _() to calls to error()Jeff Hostetler via GitGitGadget, Mar 11, 2022
  28. 16/16 fsmonitor-settings: simplify initialization of settings dataJeff Hostetler via GitGitGadget, Mar 11, 2022
  29. Junio C HamanoMar 14, 2022
  30. Jeff HostetlerMar 15, 2022
  31. Junio C HamanoMar 15, 2022
  32. Junio C HamanoMar 13, 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.