git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] builtin/credential-cache--daemon: fix error when "exit"ing on Cygwin
@ 2024-10-16 14:21 Patrick Steinhardt
  2024-10-16 14:55 ` Jeff King
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Patrick Steinhardt @ 2024-10-16 14:21 UTC (permalink / raw)
  To: git; +Cc: Adam Dinwoodie, Jeff King

Clients can signal the git-credential-cache(1) daemon that it is
supposed to exit by sending it an "exit" command. The details around
how exactly the daemon exits seem to be rather intricate as spelt out by
a comment surrounding our call to exit(3p), as we need to be mindful
around closing the client streams before we signal the client.

The logic is broken on Cygwin though: when a client asks the daemon to
exit, they won't see the EOF and will instead get an error message:

  fatal: read error from cache daemon: Software caused connection abort

This issue is known in Cygwin, see for example [1], but the exact root
cause is not known.

As it turns out, we can avoid the issue by explicitly closing the client
streams via fclose(3p). I'm not sure at all where the claimed atexit(3p)
handler mentioned in the comment is supposed to live, but from all I can
see we do not have any installed that would close the sockets for us. So
this leaves me with a bit of a sour taste overall.

That being said, I couldn't spot anything obviously wrong with closing
the streams ourselves, and it does fix the issue on Cygwin without any
regressions on other platforms as far as I can see. So let's go for this
fix, even though I cannot properly explain it.

[1]: https://github.com/cygporter/git/issues/51

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---

I've Cc'd Adam, who is the maintainer of the Git package in Cygwin, as
well as Peff, who is the original author of the below comment. I'd be
really happy if one of you could enlighten me here :)

Patrick

 builtin/credential-cache--daemon.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index bc22f5c6d24..5a09df5c167 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -156,13 +156,11 @@ static void serve_one_client(FILE *in, FILE *out)
 	}
 	else if (!strcmp(action.buf, "exit")) {
 		/*
-		 * It's important that we clean up our socket first, and then
-		 * signal the client only once we have finished the cleanup.
-		 * Calling exit() directly does this, because we clean up in
-		 * our atexit() handler, and then signal the client when our
-		 * process actually ends, which closes the socket and gives
-		 * them EOF.
+		 * We must close our file handles before we exit such that the
+		 * client will receive an EOF.
 		 */
+		fclose(in);
+		fclose(out);
 		exit(0);
 	}
 	else if (!strcmp(action.buf, "erase"))
-- 
2.47.0.72.gef8ce8f3d4.dirty


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-05-08 20:24 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-16 14:21 [PATCH] builtin/credential-cache--daemon: fix error when "exit"ing on Cygwin Patrick Steinhardt
2024-10-16 14:55 ` Jeff King
2024-10-16 15:09   ` Jeff King
2024-10-16 15:39     ` Ramsay Jones
2024-10-16 20:28     ` Taylor Blau
2024-10-17  2:33       ` Jeff King
2024-10-17  8:46         ` Patrick Steinhardt
2024-10-17 22:58           ` Ramsay Jones
2024-10-18  4:36             ` Patrick Steinhardt
2024-10-17 20:54         ` Taylor Blau
2024-10-16 15:12 ` Ramsay Jones
2024-10-18  4:36 ` [PATCH v2] " Patrick Steinhardt
2024-10-18  5:29   ` [PATCH] credential-cache: treat ECONNABORTED like ECONNRESET Jeff King
2024-10-18  5:32     ` Patrick Steinhardt
2024-10-18 15:33     ` Ramsay Jones
2024-10-18 21:17       ` Taylor Blau
2024-10-18 21:27     ` Kristoffer Haugsbakk
2024-10-19 21:21       ` Jeff King
2024-10-20 17:08         ` Comment trailers vs. bracketed lines Kristoffer Haugsbakk
2025-05-07 16:41           ` Kristoffer Haugsbakk
2025-05-08 20:24             ` Jeff King
2025-05-07 19:20           ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).