{"thread":{"id":"56867","subject":"[PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation","startedAt":"2021-11-10T11:09:15Z","lastAt":"2021-11-12T08:51:15Z","messageCount":3,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano","Adam Dinwoodie"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"440825","messageId":"pull.1074.git.1636542550889.gitgitgadget@gmail.com","threadId":"56867","inReplyTo":null,"subject":"[PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2021-11-10T11:09:10Z","receivedAt":"2021-11-10T11:09:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nCygwin emulates Unix sockets by writing files with custom contents and\nthen marking them as system files.\n\nThe tricky problem is that while the file is written and its `system`\nbit is set, it is still identified as a file. This caused test failures\nwhen Git is too fast looking for the Unix sockets and then complains\nthat there is a plain file in the way.\n\nLet's work around this by adding a delayed retry loop, specifically for\nCygwin.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    simple-ipc: work around issues with Cygwin's Unix socket emulation\n    \n    Adam Dinwoodie reported problems running the simple-ipc tests on Cygwin\n    [https://lore.kernel.org/git/20211104194619.GA12886@dinwoodie.org]. This\n    patch works around the underlying problem, which is rooted in Cygwin's\n    implementation details.\n    \n    With this patch, I could not reproduce the problem, even with sh\n    t0052-simple-ipc.sh --stress-limit=30.\n    \n    As per Junio's encouragement\n    [https://lore.kernel.org/git/xmqqee7ozyx4.fsf@gitster.g], I am\n    submitting this still in the -rc phase, hoping that it will make it into\n    v2.34.0 final.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1074%2Fdscho%2Fcygwin-vs-simple-ipc-workaround-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1074/dscho/cygwin-vs-simple-ipc-workaround-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1074\n\n compat/simple-ipc/ipc-unix-socket.c | 22 ++++++++++++++++++++++\n 1 file changed, 22 insertions(+)\n\ndiff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c\nindex 4e28857a0a1..28a79289d4f 100644\n--- a/compat/simple-ipc/ipc-unix-socket.c\n+++ b/compat/simple-ipc/ipc-unix-socket.c\n@@ -35,6 +35,28 @@ enum ipc_active_state ipc_get_active_state(const char *path)\n \t\t}\n \t}\n \n+#ifdef __CYGWIN__\n+\t/*\n+\t * Cygwin emulates Unix sockets by writing special-crafted files whose\n+\t * `system` bit is set.\n+\t *\n+\t * If we are too fast, Cygwin might still be in the process of marking\n+\t * the underlying file as a system file. Until then, we will not see a\n+\t * Unix socket here, but a plain file instead. Just in case that this\n+\t * is happening, wait a little and try again.\n+\t */\n+\t{\n+\t\tstatic const int delay[] = { 1, 10, 20, 40, -1 };\n+\t\tint i;\n+\n+\t\tfor (i = 0; S_ISREG(st.st_mode) && delay[i] > 0; i++) {\n+\t\t\tsleep_millisec(delay[i]);\n+\t\t\tif (lstat(path, &st) == -1)\n+\t\t\t\treturn IPC_STATE__INVALID_PATH;\n+\t\t}\n+\t}\n+#endif\n+\n \t/* also complain if a plain file is in the way */\n \tif ((st.st_mode & S_IFMT) != S_IFSOCK)\n \t\treturn IPC_STATE__INVALID_PATH;\n\nbase-commit: 6c220937e2b26d85920bf2d38ff2464a0d57fd6b\n-- \ngitgitgadget\n"},{"id":"440853","messageId":"xmqqtugkx7e2.fsf@gitster.g","threadId":"56867","inReplyTo":"pull.1074.git.1636542550889.gitgitgadget@gmail.com","subject":"Re: [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-11-10T17:11:49Z","receivedAt":"2021-11-10T17:11:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> Cygwin emulates Unix sockets by writing files with custom contents and\n> then marking them as system files.\n>\n> The tricky problem is that while the file is written and its `system`\n> bit is set, it is still identified as a file. This caused test failures\n> when Git is too fast looking for the Unix sockets and then complains\n> that there is a plain file in the way.\n>\n> Let's work around this by adding a delayed retry loop, specifically for\n> Cygwin.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\nOK, I was about to ask for an Ack from Cygwin folks but I see the\noriginal that got Ack is more-or-less the same except for placement\nof the comments (and this version of course is more polished than\nthe \"this should work---please try it\" version), so let me pretend\nthat this got tested-by from those who were happy with the original\nin the old thread.\n\nThanks.\n\n\n>     simple-ipc: work around issues with Cygwin's Unix socket emulation\n>     \n>     Adam Dinwoodie reported problems running the simple-ipc tests on Cygwin\n>     [https://lore.kernel.org/git/20211104194619.GA12886@dinwoodie.org]. This\n>     patch works around the underlying problem, which is rooted in Cygwin's\n>     implementation details.\n>     \n>     With this patch, I could not reproduce the problem, even with sh\n>     t0052-simple-ipc.sh --stress-limit=30.\n>     \n>     As per Junio's encouragement\n>     [https://lore.kernel.org/git/xmqqee7ozyx4.fsf@gitster.g], I am\n>     submitting this still in the -rc phase, hoping that it will make it into\n>     v2.34.0 final.\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1074%2Fdscho%2Fcygwin-vs-simple-ipc-workaround-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1074/dscho/cygwin-vs-simple-ipc-workaround-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1074\n>\n>  compat/simple-ipc/ipc-unix-socket.c | 22 ++++++++++++++++++++++\n>  1 file changed, 22 insertions(+)\n>\n> diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c\n> index 4e28857a0a1..28a79289d4f 100644\n> --- a/compat/simple-ipc/ipc-unix-socket.c\n> +++ b/compat/simple-ipc/ipc-unix-socket.c\n> @@ -35,6 +35,28 @@ enum ipc_active_state ipc_get_active_state(const char *path)\n>  \t\t}\n>  \t}\n>  \n> +#ifdef __CYGWIN__\n> +\t/*\n> +\t * Cygwin emulates Unix sockets by writing special-crafted files whose\n> +\t * `system` bit is set.\n> +\t *\n> +\t * If we are too fast, Cygwin might still be in the process of marking\n> +\t * the underlying file as a system file. Until then, we will not see a\n> +\t * Unix socket here, but a plain file instead. Just in case that this\n> +\t * is happening, wait a little and try again.\n> +\t */\n> +\t{\n> +\t\tstatic const int delay[] = { 1, 10, 20, 40, -1 };\n> +\t\tint i;\n> +\n> +\t\tfor (i = 0; S_ISREG(st.st_mode) && delay[i] > 0; i++) {\n> +\t\t\tsleep_millisec(delay[i]);\n> +\t\t\tif (lstat(path, &st) == -1)\n> +\t\t\t\treturn IPC_STATE__INVALID_PATH;\n> +\t\t}\n> +\t}\n> +#endif\n> +\n>  \t/* also complain if a plain file is in the way */\n>  \tif ((st.st_mode & S_IFMT) != S_IFSOCK)\n>  \t\treturn IPC_STATE__INVALID_PATH;\n>\n> base-commit: 6c220937e2b26d85920bf2d38ff2464a0d57fd6b\n"},{"id":"440972","messageId":"CA+kUOanaVM183qtubr+=eLebm2G3+tQwMF2PAHT_xfeeNNHr+w@mail.gmail.com","threadId":"56867","inReplyTo":"xmqqtugkx7e2.fsf@gitster.g","subject":"Re: [PATCH] simple-ipc: work around issues with Cygwin's Unix socket emulation","fromName":"Adam Dinwoodie","fromEmail":"adam@dinwoodie.org","sentAt":"2021-11-12T08:50:33Z","receivedAt":"2021-11-12T08:51:15Z","isPatch":true,"sender":{"key":"adam@dinwoodie.org","avatar":"https://avatars.githubusercontent.com/u/1397507?v=4"},"body":"On Wed, 10 Nov 2021 at 17:11, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > Cygwin emulates Unix sockets by writing files with custom contents and\n> > then marking them as system files.\n> >\n> > The tricky problem is that while the file is written and its `system`\n> > bit is set, it is still identified as a file. This caused test failures\n> > when Git is too fast looking for the Unix sockets and then complains\n> > that there is a plain file in the way.\n> >\n> > Let's work around this by adding a delayed retry loop, specifically for\n> > Cygwin.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n>\n> OK, I was about to ask for an Ack from Cygwin folks but I see the\n> original that got Ack is more-or-less the same except for placement\n> of the comments (and this version of course is more polished than\n> the \"this should work---please try it\" version), so let me pretend\n> that this got tested-by from those who were happy with the original\n> in the old thread.\n\nLate to the party – other bits of life got in the way – but I've just\nconfirmed this appears to resolve the issue for me too.\n\nAdam\n"}]}