Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion git show exit-slowness (was: Re: [PATCH v2] Win32: fix broken pipe detection)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Erik Faye-Lund  
View profile  
 More options Apr 11 2012, 12:55 pm
From: Erik Faye-Lund <kusmab...@gmail.com>
Date: Wed, 11 Apr 2012 18:55:25 +0200
Local: Wed, Apr 11 2012 12:55 pm
Subject: Re: git show exit-slowness (was: Re: [PATCH v2] Win32: fix broken pipe detection)

On Wed, Apr 11, 2012 at 6:01 PM, Erik Faye-Lund <kusmab...@gmail.com> wrote:
> I'm sorry if this quoting is a bit confusing; when I started writing
> this e-mail it seemed superficially similar to this issue. It turns
> out it is not, but I'd still like to keep the context.

> On Tue, Apr 10, 2012 at 4:23 AM, Johannes Schindelin
> <Johannes.Schinde...@gmx.de> wrote:
>> Hi Karsten,

>> On Thu, 1 Mar 2012, karsten.bl...@dcon.de wrote:

>>> As of "Win32: Thread-safe windows console output", git-log no longer
>>> terminates when the pager process dies. [...]

>> Sorry for the long delay. Happily, I did not forget to include this in
>> time for 1.7.10.

>> Thanks so much!
>> Dscho

> It seems some variation of issue is still kind-of present, but not in
> the case I presented. However, this time it was already present before
> Karsten's patch.

> Exiting the pager on "git show" on a very big commit (typically the
> initial commit on some big project imported from some other VCS) still
> makes the process hang until git finishes outputting the diff.

> The symptoms are the same; console_thread is stuck inside ReadFile,
> which doesn't return until all the output has been written. However,
> the "git show" code-path doesn't call maybe_flush_or_die.

> Now, it seems that the big difference from performing the same test on
> linux is that wait_for_pager_signal never gets triggered. I'm guessing
> this is because the pager is supposed to issue a SIGHUP to it's parent
> process, or that a write to a disconnected pipe should issue SIGPIPE.
> This obviously doesn't work on Windows, but perhaps we can emulate
> SIGPIPE it by wrapping read/write/fread/fwrite etc and calling
> raise().

Hmm, it turns out raise(SIGPIPE) doesn't work on MSVC, as SIGPIPE
(defined by us in compat/mingw.h) isn't a valid argument to MSVC's
raise(), although signal seems to accept it (the CRT doesn't complain,
at least).

So we need to emulate it.

Here's my quick stab at fixing the problem, and it seems to do the trick:

---

diff --git a/compat/mingw.c b/compat/mingw.c
index e6f331a..d18abb9 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -375,7 +375,19 @@ ssize_t mingw_write(int fd, const void *buf, size_t count)
         * the net without changing the number of WriteFile() calls in
         * the local case.
         */
-       return write(fd, buf, min(count, 31 * 1024 * 1024));
+       int ret = write(fd, buf, min(count, 31 * 1024 * 1024));
+       if (ret < 0 && errno == EPIPE)
+               mingw_raise(SIGPIPE);
+       return ret;
+}
+
+#undef fwrite
+size_t mingw_fwrite(const void *ptr, size_t size, size_t nitems, FILE *fp)
+{
+       size_t ret = fwrite(ptr, size, nitems, fp);
+       if (ret < nitems && ferror(fp) == EPIPE)
+               mingw_raise(SIGPIPE);
+       return ret;
 }

 FILE *mingw_fopen (const char *filename, const char *otype)
@@ -1662,6 +1674,7 @@ static HANDLE timer_thread;
 static int timer_interval;
 static int one_shot;
 static sig_handler_t timer_fn = SIG_DFL;
+static sig_handler_t pipe_fn = SIG_DFL;

 /* The timer works like this:
  * The thread, ticktack(), is a trivial routine that most of the time
@@ -1768,11 +1781,37 @@ int sigaction(int sig, struct sigaction *in,
struct sigaction *out)
 #undef signal
 sig_handler_t mingw_signal(int sig, sig_handler_t handler)
 {
-       sig_handler_t old = timer_fn;
-       if (sig != SIGALRM)
+       sig_handler_t old;
+       switch (sig) {
+       case SIGALRM:
+               old = timer_fn;
+               timer_fn = handler;
+               return old;
+
+       case SIGPIPE:
+               old = pipe_fn;
+               pipe_fn = handler;
+               return old;
+
+       default:
                return signal(sig, handler);
-       timer_fn = handler;
-       return old;
+       }
+}
+
+#undef raise
+int mingw_raise(int sig)
+{
+       if (sig == SIGPIPE) {
+               if (pipe_fn == SIG_DFL) {
+                       fprintf(stderr, "Program terminated with signal SIGPIPE, Broken pipe.\n");
+                       exit(SIGPIPE + 128);
+               }
+               if (pipe_fn != SIG_IGN)
+                       pipe_fn(SIGPIPE);
+               return 0;
+       }
+
+       return raise(sig);
 }

 static const char *make_backslash_path(const char *path)
diff --git a/compat/mingw.h b/compat/mingw.h
index ad87177..c7b2cec 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -176,6 +176,9 @@ int mingw_open (const char *filename, int oflags, ...);
 ssize_t mingw_write(int fd, const void *buf, size_t count);
 #define write mingw_write

+size_t mingw_fwrite(const void *ptr, size_t size, size_t nitems, FILE *fp);
+#define fwrite mingw_fwrite
+
 FILE *mingw_fopen (const char *filename, const char *otype);
 #define fopen mingw_fopen

@@ -300,6 +303,9 @@ static inline unsigned int git_ntohl(unsigned int x)
 sig_handler_t mingw_signal(int sig, sig_handler_t handler);
 #define signal mingw_signal

+int mingw_raise(int sig);
+#define raise mingw_raise
+
 /*
  * ANSI emulation wrappers
  */


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.