* [PATCH] wrapper: add workaround for open() returning EINTR @ 2021-02-24 4:43 Jeff King 2021-02-24 4:46 ` Jeff King ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Jeff King @ 2021-02-24 4:43 UTC (permalink / raw) To: git; +Cc: Aleksey Kliger On some platforms, open() reportedly returns EINTR when opening regular files and we receive a signal (usually SIGALRM from our progress meter). This shouldn't happen, as open() should be a restartable syscall, and we specify SA_RESTART when setting up the alarm handler. So it may actually be a kernel or libc bug for this to happen. But it has been reported on at least one version of Linux (on a network filesystem): https://lore.kernel.org/git/c8061cce-71e4-17bd-a56a-a5fed93804da@neanderfunk.de/ as well as on macOS starting with Big Sur even on a regular filesystem. We can work around it by retrying open() calls that get EINTR, just as we do for read(), etc. Since we don't ever _want_ to interrupt an open() call, we can get away with just redefining open, rather than insisting all callsites use xopen(). We actually do have an xopen() wrapper already (and it even does this retry, though there's no indication of it being an observed problem back then; it seems simply to have been lifted from xread(), etc). But it is used hardly anywhere, and isn't suitable for general use because it will die() on error. In theory we could combine the two, but it's awkward to do so because of the variable-args interface of open(). The workaround here is enabled all the time, without a Makefile knob, since it's a complete noop if open() never returns EINTR. I did push it into its own compat/ source file, though, since it has to #undef our macro redirection. Putting it in a file with other code risks confusion if more code is added after that #undef. Reported-by: Aleksey Kliger <alklig@microsoft.com> Signed-off-by: Jeff King <peff@peff.net> --- This was reported to me off-list. Aleksey was kind enough to test the patch on a system that was reliably showing the problem during the checkout phase of git-clone (which naturally has both a progress meter and is calling open() on a ton of files). I do still think the OS is doing the wrong thing here. But even if I'm right, it's probably prudent to work around it. git-compat-util.h | 4 ++++ wrapper.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/git-compat-util.h b/git-compat-util.h index 838246289c..2be022c422 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -788,6 +788,10 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap); #endif +#undef open +#define open git_open_with_retry +int git_open_with_retry(const char *path, int flag, ...); + #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL diff --git a/wrapper.c b/wrapper.c index bcda41e374..130f441064 100644 --- a/wrapper.c +++ b/wrapper.c @@ -678,3 +678,32 @@ int is_empty_or_missing_file(const char *filename) return !st.st_size; } + +/* + * Do not add other callers of open() after this. Our redefinition + * below will ensure the compiler catches any. + */ +#undef open +int git_open_with_retry(const char *path, int flags, ...) +{ + mode_t mode = 0; + int ret; + + /* + * Also O_TMPFILE would take a mode, but it isn't defined everywhere. + * And anyway, we don't use it in our code base. + */ + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + do { + ret = open(path, flags, mode); + } while (ret < 0 && errno == EINTR); + + return ret; +} +#define open do_not_allow_use_of_bare_open -- 2.30.1.1095.g03347429ea ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 4:43 [PATCH] wrapper: add workaround for open() returning EINTR Jeff King @ 2021-02-24 4:46 ` Jeff King 2021-02-24 5:36 ` Junio C Hamano 2021-02-24 4:50 ` [PATCH] wrapper: add workaround for open() returning EINTR Taylor Blau 2021-02-24 7:20 ` Johannes Sixt 2 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2021-02-24 4:46 UTC (permalink / raw) To: git; +Cc: Aleksey Kliger On Tue, Feb 23, 2021 at 11:43:16PM -0500, Jeff King wrote: > The workaround here is enabled all the time, without a Makefile knob, > since it's a complete noop if open() never returns EINTR. I did push it > into its own compat/ source file, though, since it has to #undef our > macro redirection. Putting it in a file with other code risks confusion > if more code is added after that #undef. Whoops, sorry, I had a last-minute change of heart here and just stuck it in wrapper.c with a bit of preprocessor magic to guard it. It felt weird having compat/open.c, when the rest of compat/ is always conditional on Makefile knobs. But I'm happy to go the other way if anybody feels strongly. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 4:46 ` Jeff King @ 2021-02-24 5:36 ` Junio C Hamano 2021-02-24 18:20 ` Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Junio C Hamano @ 2021-02-24 5:36 UTC (permalink / raw) To: Jeff King; +Cc: git, Aleksey Kliger Jeff King <peff@peff.net> writes: > On Tue, Feb 23, 2021 at 11:43:16PM -0500, Jeff King wrote: > >> The workaround here is enabled all the time, without a Makefile knob, >> since it's a complete noop if open() never returns EINTR. I did push it >> into its own compat/ source file, though, since it has to #undef our >> macro redirection. Putting it in a file with other code risks confusion >> if more code is added after that #undef. > > Whoops, sorry, I had a last-minute change of heart here and just stuck > it in wrapper.c with a bit of preprocessor magic to guard it. It felt > weird having compat/open.c, when the rest of compat/ is always > conditional on Makefile knobs. But I'm happy to go the other way if > anybody feels strongly. Hmph, just like other workarounds, shouldn't this be "if your platform screws this up, define this knob to work it around"? That would make it fit better with the rest of compat/. I dunno. A no-op wrapper makes the code less transparent, which I am somewhat unhappy. But a wrapper that is always used even on platforms that do not need might give us a better chance of noticing a bug in the wrapper itself, making it less likely for us to leave only the users of minority broken platforms behind. So... ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 5:36 ` Junio C Hamano @ 2021-02-24 18:20 ` Jeff King 2021-02-26 6:14 ` [PATCH v2] Makefile: add OPEN_RETURNS_EINTR knob Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2021-02-24 18:20 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Aleksey Kliger On Tue, Feb 23, 2021 at 09:36:25PM -0800, Junio C Hamano wrote: > Jeff King <peff@peff.net> writes: > > > On Tue, Feb 23, 2021 at 11:43:16PM -0500, Jeff King wrote: > > > >> The workaround here is enabled all the time, without a Makefile knob, > >> since it's a complete noop if open() never returns EINTR. I did push it > >> into its own compat/ source file, though, since it has to #undef our > >> macro redirection. Putting it in a file with other code risks confusion > >> if more code is added after that #undef. > > > > Whoops, sorry, I had a last-minute change of heart here and just stuck > > it in wrapper.c with a bit of preprocessor magic to guard it. It felt > > weird having compat/open.c, when the rest of compat/ is always > > conditional on Makefile knobs. But I'm happy to go the other way if > > anybody feels strongly. > > Hmph, just like other workarounds, shouldn't this be "if your > platform screws this up, define this knob to work it around"? That > would make it fit better with the rest of compat/. I actually started that way, but then I got stuck deciding which platforms in config.mak.uname to enable it for. We've seen it on Linux and on macOS. I don't know how prevalent it is on those platforms (or whether it is indeed a bug that may even get fixed). Since the check is basically zero-cost at run-time, it seemed like it was worth just being on guard for it so that nobody ever had to worry about it again. But I don't feel that strongly. I'd be happy to do it with a Makefile knob if you prefer. > I dunno. A no-op wrapper makes the code less transparent, which I > am somewhat unhappy. Yeah. I think the run-time cost is essentially zero, but it does add a bit of complexity if you are debugging. And handling the magic mode vararg definitely makes it uglier. The other thing that gives me pause is that there may be other syscalls which need the same treatment. Here's a recent discussion that Big Sur may also return EINTR from the opendir() family: https://github.com/dotnet/runtime/issues/47584 Git is presumably susceptible to that, too; it's just that we call open() a lot more frequently, so that was the obvious one that came up. I don't think there is a more general way to address this, though. We'd have to wrap each suspected syscall (but we could presumably at least tie them all to a single Makefile knob). I'm not excited at the prospect of preemptively adding such wrappers when we aren't even 100% sure that there is a problem. > But a wrapper that is always used even on > platforms that do not need might give us a better chance of noticing > a bug in the wrapper itself, making it less likely for us to leave > only the users of minority broken platforms behind. So... That part I'm less worried about. It sounds like we'd want it on for recent versions of macOS, which would give us pretty wide coverage to notice a bug. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] Makefile: add OPEN_RETURNS_EINTR knob 2021-02-24 18:20 ` Jeff King @ 2021-02-26 6:14 ` Jeff King 2021-02-26 22:17 ` Junio C Hamano 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2021-02-26 6:14 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Aleksey Kliger On Wed, Feb 24, 2021 at 01:20:44PM -0500, Jeff King wrote: > > Hmph, just like other workarounds, shouldn't this be "if your > > platform screws this up, define this knob to work it around"? That > > would make it fit better with the rest of compat/. > > I actually started that way, but then I got stuck deciding which > platforms in config.mak.uname to enable it for. We've seen it on Linux > and on macOS. I don't know how prevalent it is on those platforms (or > whether it is indeed a bug that may even get fixed). Since the check is > basically zero-cost at run-time, it seemed like it was worth just being > on guard for it so that nobody ever had to worry about it again. > > But I don't feel that strongly. I'd be happy to do it with a Makefile > knob if you prefer. So here's a v2 that turns it into a Makefile knob. This was motivated by two things: - it must not be enabled on Windows, where it overrides the existing mingw_open() - I couldn't replicate it on a Big Sur machine, using the same sequence that Aleksey did (basically just cloning and checking out dotnet/runtime.git from scratch). So it's not entirely clear to me how widespread the problem is. A conservative approach (at least in terms of change from the status quo) is to introduce this knob but not enable it automatically (which this patch does). And then if somebody runs into it, they can try turning the knob. It's less conservative in the sense that we won't be preemptively protecting people. I dunno. Once we have the knob, it would be pretty easy to just flip the default. -- >8 -- Subject: [PATCH] Makefile: add OPEN_RETURNS_EINTR knob On some platforms, open() reportedly returns EINTR when opening regular files and we receive a signal (usually SIGALRM from our progress meter). This shouldn't happen, as open() should be a restartable syscall, and we specify SA_RESTART when setting up the alarm handler. So it may actually be a kernel or libc bug for this to happen. But it has been reported on at least one version of Linux (on a network filesystem): https://lore.kernel.org/git/c8061cce-71e4-17bd-a56a-a5fed93804da@neanderfunk.de/ as well as on macOS starting with Big Sur even on a regular filesystem. We can work around it by retrying open() calls that get EINTR, just as we do for read(), etc. Since we don't ever _want_ to interrupt an open() call, we can get away with just redefining open, rather than insisting all callsites use xopen(). We actually do have an xopen() wrapper already (and it even does this retry, though there's no indication of it being an observed problem back then; it seems simply to have been lifted from xread(), etc). But it is used hardly anywhere, and isn't suitable for general use because it will die() on error. In theory we could combine the two, but it's awkward to do so because of the variable-args interface of open(). This patch adds a Makefile knob for enabling the workaround. It's not enabled by default for any platforms in config.mak.uname yet, as we don't have enough data to decide how common this is (I have not been able to reproduce on either Linux or Big Sur myself). It may be worth enabling preemptively anyway, since the cost is pretty low (if we don't see an EINTR, it's just an extra conditional). However, note that we must not enable this on Windows. It doesn't do anything there, and the macro overrides the existing mingw_open() redirection. I've added a preemptive #undef here in the mingw header (which is processed first) to just quietly disable it (we could also make it an #error, but there is little point in being so aggressive). Reported-by: Aleksey Kliger <alklig@microsoft.com> Signed-off-by: Jeff King <peff@peff.net> --- Makefile | 7 +++++++ compat/mingw.h | 1 + compat/open.c | 25 +++++++++++++++++++++++++ git-compat-util.h | 6 ++++++ 4 files changed, 39 insertions(+) create mode 100644 compat/open.c diff --git a/Makefile b/Makefile index 9b1bde2e0e..c4872ca16e 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ all:: # when attempting to read from an fopen'ed directory (or even to fopen # it at all). # +# Define OPEN_RETURNS_EINTR if your open() system call may return EINTR +# when a signal is received (as opposed to restarting). +# # Define NO_OPENSSL environment variable if you do not have OpenSSL. # # Define USE_LIBPCRE if you have and want to use libpcre. Various @@ -1538,6 +1541,10 @@ ifdef FREAD_READS_DIRECTORIES COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES COMPAT_OBJS += compat/fopen.o endif +ifdef OPEN_RETURNS_EINTR + COMPAT_CFLAGS += -DOPEN_RETURNS_EINTR + COMPAT_OBJS += compat/open.o +endif ifdef NO_SYMLINK_HEAD BASIC_CFLAGS += -DNO_SYMLINK_HEAD endif diff --git a/compat/mingw.h b/compat/mingw.h index af8eddd73e..c9a52ad64a 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -227,6 +227,7 @@ int mingw_rmdir(const char *path); int mingw_open (const char *filename, int oflags, ...); #define open mingw_open +#undef OPEN_RETURNS_EINTR int mingw_fgetc(FILE *stream); #define fgetc mingw_fgetc diff --git a/compat/open.c b/compat/open.c new file mode 100644 index 0000000000..eb3754a23b --- /dev/null +++ b/compat/open.c @@ -0,0 +1,25 @@ +#include "git-compat-util.h" + +#undef open +int git_open_with_retry(const char *path, int flags, ...) +{ + mode_t mode = 0; + int ret; + + /* + * Also O_TMPFILE would take a mode, but it isn't defined everywhere. + * And anyway, we don't use it in our code base. + */ + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + do { + ret = open(path, flags, mode); + } while (ret < 0 && errno == EINTR); + + return ret; +} diff --git a/git-compat-util.h b/git-compat-util.h index 838246289c..551cc9f22f 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -788,6 +788,12 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap); #endif +#ifdef OPEN_RETURNS_EINTR +#undef open +#define open git_open_with_retry +int git_open_with_retry(const char *path, int flag, ...); +#endif + #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL -- 2.31.0.rc0.520.g3ffb8d01f4 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] Makefile: add OPEN_RETURNS_EINTR knob 2021-02-26 6:14 ` [PATCH v2] Makefile: add OPEN_RETURNS_EINTR knob Jeff King @ 2021-02-26 22:17 ` Junio C Hamano 2021-03-01 9:29 ` [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Junio C Hamano @ 2021-02-26 22:17 UTC (permalink / raw) To: Jeff King; +Cc: git, Aleksey Kliger Jeff King <peff@peff.net> writes: > However, note that we must not enable this on Windows. It doesn't do > anything there, and the macro overrides the existing mingw_open() > redirection. I've added a preemptive #undef here in the mingw header > (which is processed first) to just quietly disable it (we could also > make it an #error, but there is little point in being so aggressive). > ... > diff --git a/compat/open.c b/compat/open.c > new file mode 100644 > index 0000000000..eb3754a23b > --- /dev/null > +++ b/compat/open.c > @@ -0,0 +1,25 @@ > +#include "git-compat-util.h" > + > +#undef open > +int git_open_with_retry(const char *path, int flags, ...) > +{ > + mode_t mode = 0; > + int ret; > + > + /* > + * Also O_TMPFILE would take a mode, but it isn't defined everywhere. > + * And anyway, we don't use it in our code base. > + */ That is being extra careful---I like it very much. > + if (flags & O_CREAT) { > + va_list ap; > + va_start(ap, flags); > + mode = va_arg(ap, int); > + va_end(ap); > + } > + > + do { > + ret = open(path, flags, mode); > + } while (ret < 0 && errno == EINTR); > + > + return ret; > +} Thanks. > diff --git a/git-compat-util.h b/git-compat-util.h > index 838246289c..551cc9f22f 100644 > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -788,6 +788,12 @@ int git_vsnprintf(char *str, size_t maxsize, > const char *format, va_list ap); > #endif > > +#ifdef OPEN_RETURNS_EINTR > +#undef open > +#define open git_open_with_retry > +int git_open_with_retry(const char *path, int flag, ...); > +#endif > + > #ifdef __GLIBC_PREREQ > #if __GLIBC_PREREQ(2, 1) > #define HAVE_STRCHRNUL ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur 2021-02-26 22:17 ` Junio C Hamano @ 2021-03-01 9:29 ` Jeff King 2021-03-01 17:17 ` Junio C Hamano 2021-03-01 23:57 ` Junio C Hamano 0 siblings, 2 replies; 15+ messages in thread From: Jeff King @ 2021-03-01 9:29 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Aleksey Kliger On Fri, Feb 26, 2021 at 02:17:53PM -0800, Junio C Hamano wrote: > > + /* > > + * Also O_TMPFILE would take a mode, but it isn't defined everywhere. > > + * And anyway, we don't use it in our code base. > > + */ > > That is being extra careful---I like it very much. I wondered what would happen if my "anyway" above is wrong. We at least would not invoke undefined behavior (because we'd avoid looking at the mode parameter even though it exists), but would pass a "0" mode to the real open(). Presumably somebody would notice that. :) > > + if (flags & O_CREAT) { > > + va_list ap; > > + va_start(ap, flags); > > + mode = va_arg(ap, int); > > + va_end(ap); > > + } > > + > > + do { > > + ret = open(path, flags, mode); > > + } while (ret < 0 && errno == EINTR); > > + > > + return ret; > > +} > > Thanks. I got another off-list report of the problem. I think we probably want to do this on top: -- >8 -- Subject: config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur We've had mixed reports on whether the latest release of macOS needs this Makefile knob set. In most reported cases, there's antivirus software running (which one might imagine could cause an open() call to be delayed). However, one of the (off-list) reports I've gotten indicated that it happened on an otherwise clean install of Big Sur. Since the symptom is so bad (checkout randomly fails to write several fails when the progress meter kicks in), and since the workaround is so lightweight (if we don't see EINTR, it's just an extra conditional check), let's just turn it on by default. Signed-off-by: Jeff King <peff@peff.net> --- Apparently Big Sur jumped from macOS 10.x to 11.x. But our "uname -r" check gives the "Darwin version", in which it is 20.x (following 19.x for the previous version). At least according to some sources I found online. :) So that is good, because otherwise all of our uname_R checks here would have been broken. I don't have a Big Sur machine handy to test with, but I believe this should do what we want. config.mak.uname | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.mak.uname b/config.mak.uname index e22d4b6d67..d204c20a64 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -124,6 +124,9 @@ ifeq ($(uname_S),Darwin) ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 11 && echo 1),1) HAVE_GETDELIM = YesPlease endif + ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 20 && echo 1),1) + OPEN_RETURNS_EINTR = UnfortunatelyYes + endif NO_MEMMEM = YesPlease USE_ST_TIMESPEC = YesPlease HAVE_DEV_TTY = YesPlease -- 2.31.0.rc0.521.g56be7fa5e1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur 2021-03-01 9:29 ` [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Jeff King @ 2021-03-01 17:17 ` Junio C Hamano 2021-03-01 23:57 ` Junio C Hamano 1 sibling, 0 replies; 15+ messages in thread From: Junio C Hamano @ 2021-03-01 17:17 UTC (permalink / raw) To: Jeff King; +Cc: git, Aleksey Kliger Jeff King <peff@peff.net> writes: > I got another off-list report of the problem. I think we probably want > to do this on top: > > -- >8 -- > Subject: config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur > > We've had mixed reports on whether the latest release of macOS needs > this Makefile knob set. In most reported cases, there's antivirus > software running (which one might imagine could cause an open() call to > be delayed). However, one of the (off-list) reports I've gotten > indicated that it happened on an otherwise clean install of Big Sur. > > Since the symptom is so bad (checkout randomly fails to write several > fails when the progress meter kicks in), and since the workaround is so > lightweight (if we don't see EINTR, it's just an extra conditional > check), let's just turn it on by default. > > Signed-off-by: Jeff King <peff@peff.net> > --- > Apparently Big Sur jumped from macOS 10.x to 11.x. But our "uname -r" > check gives the "Darwin version", in which it is 20.x (following 19.x > for the previous version). At least according to some sources I found > online. :) So that is good, because otherwise all of our uname_R checks > here would have been broken. I don't have a Big Sur machine handy to > test with, but I believe this should do what we want. Thanks. > config.mak.uname | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/config.mak.uname b/config.mak.uname > index e22d4b6d67..d204c20a64 100644 > --- a/config.mak.uname > +++ b/config.mak.uname > @@ -124,6 +124,9 @@ ifeq ($(uname_S),Darwin) > ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 11 && echo 1),1) > HAVE_GETDELIM = YesPlease > endif > + ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 20 && echo 1),1) > + OPEN_RETURNS_EINTR = UnfortunatelyYes > + endif > NO_MEMMEM = YesPlease > USE_ST_TIMESPEC = YesPlease > HAVE_DEV_TTY = YesPlease ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur 2021-03-01 9:29 ` [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Jeff King 2021-03-01 17:17 ` Junio C Hamano @ 2021-03-01 23:57 ` Junio C Hamano 2021-03-03 13:41 ` Jeff King 1 sibling, 1 reply; 15+ messages in thread From: Junio C Hamano @ 2021-03-01 23:57 UTC (permalink / raw) To: Jeff King, Joachim Schmitz, Matt Kraai, Randall S. Becker Cc: git, Aleksey Kliger Jeff King <peff@peff.net> writes: > I got another off-list report of the problem. I think we probably want > to do this on top: Queued and pushed out. I wonder if these hits for SA_RESTART in config.mak.uname would be a good way to guide us. [6c109904 (Port to HP NonStop, 2012-09-19)] # Not detected (nor checked for) by './configure'. # We don't have SA_RESTART on NonStop, unfortunalety. COMPAT_CFLAGS += -DSA_RESTART=0 [40036bed (Port to QNX, 2012-12-18)] ifeq ($(uname_S),QNX) COMPAT_CFLAGS += -DSA_RESTART=0 One caveat is that we do not know if their system headers hide the real implementation of open(2) behind a C preprocessor macro, in whcih case OPEN_RETURNS_EINTR wrapper may not work correctly. > config.mak.uname | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/config.mak.uname b/config.mak.uname > index e22d4b6d67..d204c20a64 100644 > --- a/config.mak.uname > +++ b/config.mak.uname > @@ -124,6 +124,9 @@ ifeq ($(uname_S),Darwin) > ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 11 && echo 1),1) > HAVE_GETDELIM = YesPlease > endif > + ifeq ($(shell test "`expr "$(uname_R)" : '\([0-9][0-9]*\)\.'`" -ge 20 && echo 1),1) > + OPEN_RETURNS_EINTR = UnfortunatelyYes > + endif > NO_MEMMEM = YesPlease > USE_ST_TIMESPEC = YesPlease > HAVE_DEV_TTY = YesPlease ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur 2021-03-01 23:57 ` Junio C Hamano @ 2021-03-03 13:41 ` Jeff King 2021-03-04 0:47 ` Junio C Hamano 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2021-03-03 13:41 UTC (permalink / raw) To: Junio C Hamano Cc: Joachim Schmitz, Matt Kraai, Randall S. Becker, git, Aleksey Kliger On Mon, Mar 01, 2021 at 03:57:35PM -0800, Junio C Hamano wrote: > Jeff King <peff@peff.net> writes: > > > I got another off-list report of the problem. I think we probably want > > to do this on top: > > Queued and pushed out. Thanks. I guess we're a bit late to make it into the upcoming release. Certainly we have survived for many years without this particular bugfix, so in that sense it is not urgent. But I do wonder if we will see more reports as more people start using the new macOS release. So it might be good to keep in mind for maint, if we cut a minor release. Or alternatively, we could include _just_ the first patch. That's low risk, since you have to enable to knob yourself, but it gives people an option if they run into the symptom. But even that is probably not that urgent. People can also cherry-pick the patch, after all (and a distributor like homebrew can probably include the patch in their recipe if need be). > I wonder if these hits for SA_RESTART in config.mak.uname would be a > good way to guide us. > > [6c109904 (Port to HP NonStop, 2012-09-19)] > # Not detected (nor checked for) by './configure'. > # We don't have SA_RESTART on NonStop, unfortunalety. > COMPAT_CFLAGS += -DSA_RESTART=0 > > [40036bed (Port to QNX, 2012-12-18)] > ifeq ($(uname_S),QNX) > COMPAT_CFLAGS += -DSA_RESTART=0 I'm inclined to leave them alone until somebody with access to such a system can look further into it. After all, if you do not have SA_RESTART, you might not even have EINTR in the first place. > One caveat is that we do not know if their system headers hide the > real implementation of open(2) behind a C preprocessor macro, in > whcih case OPEN_RETURNS_EINTR wrapper may not work correctly. Yeah. I didn't think about that when I did the original "just do it everywhere" patch. But that is exactly what caused the problem on Windows (not a system macro, but in fact our own!). So I'm glad to have backed it off to a Makefile knob. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur 2021-03-03 13:41 ` Jeff King @ 2021-03-04 0:47 ` Junio C Hamano 0 siblings, 0 replies; 15+ messages in thread From: Junio C Hamano @ 2021-03-04 0:47 UTC (permalink / raw) To: Jeff King Cc: Joachim Schmitz, Matt Kraai, Randall S. Becker, git, Aleksey Kliger Jeff King <peff@peff.net> writes: > Thanks. I guess we're a bit late to make it into the upcoming release. > Certainly we have survived for many years without this particular > bugfix, so in that sense it is not urgent. But I do wonder if we will > see more reports as more people start using the new macOS release. So it > might be good to keep in mind for maint, if we cut a minor release. > > Or alternatively, we could include _just_ the first patch. That's low > risk, since you have to enable to knob yourself, but it gives people an > option if they run into the symptom. But even that is probably not that > urgent. People can also cherry-pick the patch, after all (and a > distributor like homebrew can probably include the patch in their recipe > if need be). True. The topic is forked at somewhere mergeable to 'maint' so distro folks who are interested can merge them down later. I think it is small and safe enough to merge them both down to the upcoming release, though. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 4:43 [PATCH] wrapper: add workaround for open() returning EINTR Jeff King 2021-02-24 4:46 ` Jeff King @ 2021-02-24 4:50 ` Taylor Blau 2021-02-24 7:20 ` Johannes Sixt 2 siblings, 0 replies; 15+ messages in thread From: Taylor Blau @ 2021-02-24 4:50 UTC (permalink / raw) To: Jeff King; +Cc: git, Aleksey Kliger On Tue, Feb 23, 2021 at 11:43:15PM -0500, Jeff King wrote: > The workaround here is enabled all the time, without a Makefile knob, > since it's a complete noop if open() never returns EINTR. I did push it > into its own compat/ source file, though, since it has to #undef our > macro redirection. Putting it in a file with other code risks confusion > if more code is added after that #undef. Hmm. The patch below defines it in wrapper.c. Intentional? > I do still think the OS is doing the wrong thing here. But even if I'm > right, it's probably prudent to work around it. Regardless of the above, I agree that if your explanation is true (and I have no reason to believe that it isn't) that the OS is indeed doing the wrong thing here. That patch below looks quite reasonable, thanks. Thanks, Taylor ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 4:43 [PATCH] wrapper: add workaround for open() returning EINTR Jeff King 2021-02-24 4:46 ` Jeff King 2021-02-24 4:50 ` [PATCH] wrapper: add workaround for open() returning EINTR Taylor Blau @ 2021-02-24 7:20 ` Johannes Sixt 2021-02-24 18:23 ` Jeff King 2 siblings, 1 reply; 15+ messages in thread From: Johannes Sixt @ 2021-02-24 7:20 UTC (permalink / raw) To: Jeff King, git; +Cc: Aleksey Kliger Am 24.02.21 um 05:43 schrieb Jeff King: > The workaround here is enabled all the time, without a Makefile knob, > since it's a complete noop if open() never returns EINTR. I did push it > into its own compat/ source file, though, since it has to #undef our > macro redirection. Putting it in a file with other code risks confusion > if more code is added after that #undef. I'm not so much opposed to "enable it all the time" in general, but when we already have an override of open(), like for the Windows case in compat/mingw.h, I find it a bit rough to put another wrapper around it, even more so since we won't have the EINTR problem on Windows due to the absence of signals. -- Hannes ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 7:20 ` Johannes Sixt @ 2021-02-24 18:23 ` Jeff King 2021-02-26 6:17 ` Jeff King 0 siblings, 1 reply; 15+ messages in thread From: Jeff King @ 2021-02-24 18:23 UTC (permalink / raw) To: Johannes Sixt; +Cc: git, Aleksey Kliger On Wed, Feb 24, 2021 at 08:20:57AM +0100, Johannes Sixt wrote: > Am 24.02.21 um 05:43 schrieb Jeff King: > > The workaround here is enabled all the time, without a Makefile knob, > > since it's a complete noop if open() never returns EINTR. I did push it > > into its own compat/ source file, though, since it has to #undef our > > macro redirection. Putting it in a file with other code risks confusion > > if more code is added after that #undef. > > I'm not so much opposed to "enable it all the time" in general, but when > we already have an override of open(), like for the Windows case in > compat/mingw.h, I find it a bit rough to put another wrapper around it, > even more so since we won't have the EINTR problem on Windows due to the > absence of signals. That's fair. I don't think my new wrapper would interact well with mingw_open(). They are both trying to #define open. I think since mine comes later in git-compat-util.h, it is probably overriding mingw_open() completely on Windows, which is quite bad (we call into my function in wrapper.c, but then its "#undef open" means we get the original open(), not the previously defined wrapper). -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] wrapper: add workaround for open() returning EINTR 2021-02-24 18:23 ` Jeff King @ 2021-02-26 6:17 ` Jeff King 0 siblings, 0 replies; 15+ messages in thread From: Jeff King @ 2021-02-26 6:17 UTC (permalink / raw) To: Johannes Sixt; +Cc: git, Aleksey Kliger On Wed, Feb 24, 2021 at 01:23:51PM -0500, Jeff King wrote: > > I'm not so much opposed to "enable it all the time" in general, but when > > we already have an override of open(), like for the Windows case in > > compat/mingw.h, I find it a bit rough to put another wrapper around it, > > even more so since we won't have the EINTR problem on Windows due to the > > absence of signals. > > That's fair. I don't think my new wrapper would interact well with > mingw_open(). They are both trying to #define open. I think since mine > comes later in git-compat-util.h, it is probably overriding mingw_open() > completely on Windows, which is quite bad (we call into my function in > wrapper.c, but then its "#undef open" means we get the original open(), > not the previously defined wrapper). Thanks again for pointing out mingw_open(). The v2 I posted should avoid any bad interactions there, even if we do end up enabling it all the time. By the way, I did notice something funny when looking at mingw_open(). It unconditionally does: va_start(args, oflags); mode = va_arg(args, int); va_end(args); no matter what we see in oflags. But callers who are not passing O_CREAT will not provide a third argument at all. So probably it is loading random trash from the stack and passing it around in the "mode" variable. This doesn't hurt anything, because ultimately we pass the trash along to the real open function, which will ignore it without O_CREAT. But it is definitely undefined behavior to call va_arg() at all in this instance. -Peff ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-03-04 1:11 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-02-24 4:43 [PATCH] wrapper: add workaround for open() returning EINTR Jeff King 2021-02-24 4:46 ` Jeff King 2021-02-24 5:36 ` Junio C Hamano 2021-02-24 18:20 ` Jeff King 2021-02-26 6:14 ` [PATCH v2] Makefile: add OPEN_RETURNS_EINTR knob Jeff King 2021-02-26 22:17 ` Junio C Hamano 2021-03-01 9:29 ` [PATCH] config.mak.uname: enable OPEN_RETURNS_EINTR for macOS Big Sur Jeff King 2021-03-01 17:17 ` Junio C Hamano 2021-03-01 23:57 ` Junio C Hamano 2021-03-03 13:41 ` Jeff King 2021-03-04 0:47 ` Junio C Hamano 2021-02-24 4:50 ` [PATCH] wrapper: add workaround for open() returning EINTR Taylor Blau 2021-02-24 7:20 ` Johannes Sixt 2021-02-24 18:23 ` Jeff King 2021-02-26 6:17 ` Jeff King
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git 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 read-only IMAP folder(s) and NNTP newsgroup(s).