All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation
@ 2021-11-10 11:09 Johannes Schindelin via GitGitGadget
  2021-11-10 17:11 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2021-11-10 11:09 UTC (permalink / raw)
  To: git
  Cc: Adam Dinwoodie, Ramsay Jones, Junio C Hamano,
	Johannes Schindelin, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

Cygwin emulates Unix sockets by writing files with custom contents and
then marking them as system files.

The tricky problem is that while the file is written and its `system`
bit is set, it is still identified as a file. This caused test failures
when Git is too fast looking for the Unix sockets and then complains
that there is a plain file in the way.

Let's work around this by adding a delayed retry loop, specifically for
Cygwin.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    simple-ipc: work around issues with Cygwin's Unix socket emulation
    
    Adam Dinwoodie reported problems running the simple-ipc tests on Cygwin
    [https://lore.kernel.org/git/20211104194619.GA12886@dinwoodie.org]. This
    patch works around the underlying problem, which is rooted in Cygwin's
    implementation details.
    
    With this patch, I could not reproduce the problem, even with sh
    t0052-simple-ipc.sh --stress-limit=30.
    
    As per Junio's encouragement
    [https://lore.kernel.org/git/xmqqee7ozyx4.fsf@gitster.g], I am
    submitting this still in the -rc phase, hoping that it will make it into
    v2.34.0 final.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1074%2Fdscho%2Fcygwin-vs-simple-ipc-workaround-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1074/dscho/cygwin-vs-simple-ipc-workaround-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1074

 compat/simple-ipc/ipc-unix-socket.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c
index 4e28857a0a1..28a79289d4f 100644
--- a/compat/simple-ipc/ipc-unix-socket.c
+++ b/compat/simple-ipc/ipc-unix-socket.c
@@ -35,6 +35,28 @@ enum ipc_active_state ipc_get_active_state(const char *path)
 		}
 	}
 
+#ifdef __CYGWIN__
+	/*
+	 * Cygwin emulates Unix sockets by writing special-crafted files whose
+	 * `system` bit is set.
+	 *
+	 * If we are too fast, Cygwin might still be in the process of marking
+	 * the underlying file as a system file. Until then, we will not see a
+	 * Unix socket here, but a plain file instead. Just in case that this
+	 * is happening, wait a little and try again.
+	 */
+	{
+		static const int delay[] = { 1, 10, 20, 40, -1 };
+		int i;
+
+		for (i = 0; S_ISREG(st.st_mode) && delay[i] > 0; i++) {
+			sleep_millisec(delay[i]);
+			if (lstat(path, &st) == -1)
+				return IPC_STATE__INVALID_PATH;
+		}
+	}
+#endif
+
 	/* also complain if a plain file is in the way */
 	if ((st.st_mode & S_IFMT) != S_IFSOCK)
 		return IPC_STATE__INVALID_PATH;

base-commit: 6c220937e2b26d85920bf2d38ff2464a0d57fd6b
-- 
gitgitgadget

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

* Re: [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation
  2021-11-10 11:09 [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation Johannes Schindelin via GitGitGadget
@ 2021-11-10 17:11 ` Junio C Hamano
  2021-11-12  8:50   ` Adam Dinwoodie
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2021-11-10 17:11 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget
  Cc: git, Adam Dinwoodie, Ramsay Jones, Johannes Schindelin

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> Cygwin emulates Unix sockets by writing files with custom contents and
> then marking them as system files.
>
> The tricky problem is that while the file is written and its `system`
> bit is set, it is still identified as a file. This caused test failures
> when Git is too fast looking for the Unix sockets and then complains
> that there is a plain file in the way.
>
> Let's work around this by adding a delayed retry loop, specifically for
> Cygwin.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---

OK, I was about to ask for an Ack from Cygwin folks but I see the
original that got Ack is more-or-less the same except for placement
of the comments (and this version of course is more polished than
the "this should work---please try it" version), so let me pretend
that this got tested-by from those who were happy with the original
in the old thread.

Thanks.


>     simple-ipc: work around issues with Cygwin's Unix socket emulation
>     
>     Adam Dinwoodie reported problems running the simple-ipc tests on Cygwin
>     [https://lore.kernel.org/git/20211104194619.GA12886@dinwoodie.org]. This
>     patch works around the underlying problem, which is rooted in Cygwin's
>     implementation details.
>     
>     With this patch, I could not reproduce the problem, even with sh
>     t0052-simple-ipc.sh --stress-limit=30.
>     
>     As per Junio's encouragement
>     [https://lore.kernel.org/git/xmqqee7ozyx4.fsf@gitster.g], I am
>     submitting this still in the -rc phase, hoping that it will make it into
>     v2.34.0 final.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1074%2Fdscho%2Fcygwin-vs-simple-ipc-workaround-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1074/dscho/cygwin-vs-simple-ipc-workaround-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1074
>
>  compat/simple-ipc/ipc-unix-socket.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c
> index 4e28857a0a1..28a79289d4f 100644
> --- a/compat/simple-ipc/ipc-unix-socket.c
> +++ b/compat/simple-ipc/ipc-unix-socket.c
> @@ -35,6 +35,28 @@ enum ipc_active_state ipc_get_active_state(const char *path)
>  		}
>  	}
>  
> +#ifdef __CYGWIN__
> +	/*
> +	 * Cygwin emulates Unix sockets by writing special-crafted files whose
> +	 * `system` bit is set.
> +	 *
> +	 * If we are too fast, Cygwin might still be in the process of marking
> +	 * the underlying file as a system file. Until then, we will not see a
> +	 * Unix socket here, but a plain file instead. Just in case that this
> +	 * is happening, wait a little and try again.
> +	 */
> +	{
> +		static const int delay[] = { 1, 10, 20, 40, -1 };
> +		int i;
> +
> +		for (i = 0; S_ISREG(st.st_mode) && delay[i] > 0; i++) {
> +			sleep_millisec(delay[i]);
> +			if (lstat(path, &st) == -1)
> +				return IPC_STATE__INVALID_PATH;
> +		}
> +	}
> +#endif
> +
>  	/* also complain if a plain file is in the way */
>  	if ((st.st_mode & S_IFMT) != S_IFSOCK)
>  		return IPC_STATE__INVALID_PATH;
>
> base-commit: 6c220937e2b26d85920bf2d38ff2464a0d57fd6b

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

* Re: [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation
  2021-11-10 17:11 ` Junio C Hamano
@ 2021-11-12  8:50   ` Adam Dinwoodie
  0 siblings, 0 replies; 3+ messages in thread
From: Adam Dinwoodie @ 2021-11-12  8:50 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Schindelin via GitGitGadget, git, Ramsay Jones,
	Johannes Schindelin

On Wed, 10 Nov 2021 at 17:11, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > Cygwin emulates Unix sockets by writing files with custom contents and
> > then marking them as system files.
> >
> > The tricky problem is that while the file is written and its `system`
> > bit is set, it is still identified as a file. This caused test failures
> > when Git is too fast looking for the Unix sockets and then complains
> > that there is a plain file in the way.
> >
> > Let's work around this by adding a delayed retry loop, specifically for
> > Cygwin.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
>
> OK, I was about to ask for an Ack from Cygwin folks but I see the
> original that got Ack is more-or-less the same except for placement
> of the comments (and this version of course is more polished than
> the "this should work---please try it" version), so let me pretend
> that this got tested-by from those who were happy with the original
> in the old thread.

Late to the party – other bits of life got in the way – but I've just
confirmed this appears to resolve the issue for me too.

Adam

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

end of thread, other threads:[~2021-11-12  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 11:09 [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation Johannes Schindelin via GitGitGadget
2021-11-10 17:11 ` Junio C Hamano
2021-11-12  8:50   ` Adam Dinwoodie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.