threads / discuss / 45455

Issues with git send-email and msmtp

Subject: Issues with git send-email and msmtp

## tl;dr

4 messages between Mar 21, 2017 and Mar 22, 2017.

replies: 3people: 4as markdown or json

Roger Pau Monné· Mar 21, 2017, 15:49 UTC · lore
Hello,

I'm trying to use git send-email with msmtp, and I have added the following to my .gitconfig:

[sendemail]
	smtpserver = "/usr/local/bin/msmtp"

This seems to work fine, except that sometimes git dies unexpectedly after queuing a patch to msmtp:

Died at /usr/local/Cellar/git/2.12.0/libexec/git-core/git-send-email line 1350, <FIN> line 3.

I'm guessing there's some kind of race, because this is not 100% reproducible, sometimes succeeds while others simply dies with the above message. As you can imagine, this is specially annoying when sending patch series.

Has someone seen similar issues when using send-email and msmtp? Am I missing something in my .gitconfig?

Thanks, Roger.
(please keep me in the Cc since I'm not subscribed)
Jeff King· Mar 21, 2017, 16:50 UTC · re: Roger Pau Monné · lore

Re: Issues with git send-email and msmtp

On Tue, Mar 21, 2017 at 03:49:21PM +0000, Roger Pau Monné wrote:
Show 10 quoted lines
> I'm trying to use git send-email with msmtp, and I have added the following to
> my .gitconfig:
> 
> [sendemail]
> 	smtpserver = "/usr/local/bin/msmtp"
> 
> This seems to work fine, except that sometimes git dies unexpectedly after
> queuing a patch to msmtp:
> 
> Died at /usr/local/Cellar/git/2.12.0/libexec/git-core/git-send-email line 1350, <FIN> line 3.

That line looks like it's the "close" on the pipe. If it's dying racily that could mean that msmtp for some reason is not eating all of the data and we're getting EPIPE (though that seems weird, since we're just dumping the message until EOF). Or possibly msmtp is sometimes exiting non-zero.

Capturing an "strace" for a failing run would be helpful. If that's not possible, something like this patch might help diagnose it:

diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..32d34f995 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1346,7 +1346,10 @@ EOF
 			exec($smtp_server, @sendmail_parameters) or die $!;
 		}
 		print $sm "$header\n$message";
-		close $sm or die $!;
+		if (!close($sm)) {
+			die $! ? "unable to write to $smtp_server: $!"
+			       : "smtp program '$smtp_server' exited non-zero: $?"
+		}
 	} else {
 
 		if (!defined $smtp_server) {
Eric Wong· Mar 21, 2017, 19:23 UTC · re: Jeff King · lore

Re: Issues with git send-email and msmtp

Jeff King <peff@peff.net> wrote:
Show 12 quoted lines
> On Tue, Mar 21, 2017 at 03:49:21PM +0000, Roger Pau Monné wrote:
> 
> > I'm trying to use git send-email with msmtp, and I have added the following to
> > my .gitconfig:
> > 
> > [sendemail]
> > 	smtpserver = "/usr/local/bin/msmtp"
> > 
> > This seems to work fine, except that sometimes git dies unexpectedly after
> > queuing a patch to msmtp:
> > 
> > Died at /usr/local/Cellar/git/2.12.0/libexec/git-core/git-send-email line 1350, <FIN> line 3.
Hi Roger, can you also enable msmtp logging and debugging?

logfile /path/to/log # in ~/.msmtprc And "msmtp --debug" in the command line

Show 17 quoted lines
> That line looks like it's the "close" on the pipe. If it's dying racily
> that could mean that msmtp for some reason is not eating all of the
> data and we're getting EPIPE (though that seems weird, since we're just
> dumping the message until EOF). Or possibly msmtp is sometimes exiting
> non-zero.
> 
> Capturing an "strace" for a failing run would be helpful. If that's not
> possible, something like this patch might help diagnose it:
> 
> diff --git a/git-send-email.perl b/git-send-email.perl
> index eea0a517f..32d34f995 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1346,7 +1346,10 @@ EOF
>  			exec($smtp_server, @sendmail_parameters) or die $!;
>  		}
>  		print $sm "$header\n$message";
Perhaps also:
		print $sm "$header\n$message" or
				die "print failed to $smtp_server: $!";
> -		close $sm or die $!;
> +		if (!close($sm)) {
> +			die $! ? "unable to write to $smtp_server: $!"
> +			       : "smtp program '$smtp_server' exited non-zero: $?"
Parentheses please :>
Roger Pau Monné· Mar 22, 2017, 09:47 UTC · re: Roger Pau Monné · lore

Re: Issues with git send-email and msmtp

On Tue, Mar 21, 2017 at 03:49:21PM +0000, Roger Pau Monné wrote:
Show 19 quoted lines
> Hello,
> 
> I'm trying to use git send-email with msmtp, and I have added the following to
> my .gitconfig:
> 
> [sendemail]
> 	smtpserver = "/usr/local/bin/msmtp"
> 
> This seems to work fine, except that sometimes git dies unexpectedly after
> queuing a patch to msmtp:
> 
> Died at /usr/local/Cellar/git/2.12.0/libexec/git-core/git-send-email line 1350, <FIN> line 3.
> 
> I'm guessing there's some kind of race, because this is not 100% reproducible,
> sometimes succeeds while others simply dies with the above message. As you can
> imagine, this is specially annoying when sending patch series.
> 
> Has someone seen similar issues when using send-email and msmtp? Am I missing
> something in my .gitconfig?
(switched to my @citrix.com address to prevent further bounces)
Hello,

Thanks for the help, and sorry to reply here (as some of you noted the forwarding from address with SPF was broken and messages bounced). It seems like this is a msmtp issue, more exactly msmtp doesn't handle SIGPIPE, and AFAICT this leads to crashes when the server closes the connection before msmtp does:

* thread #1: [...] stop reason = signal SIGPIPE
    frame #0: 0x00007fffd5c4d00a libsystem_kernel.dylib`__sendmsg + 10
libsystem_kernel.dylib`__sendmsg:
[...]
(lldb) bt
* thread #1: tid = 0x87c0f4, 0x00007fffd5c4d00a libsystem_kernel.dylib`__sendmsg + 10, queue = 'com.apple.main-thread', stop reason = signal SIGPIPE
  * frame #0: 0x00007fffd5c4d00a libsystem_kernel.dylib`__sendmsg + 10
    frame #1: 0x0000000101e5c69c libgnutls.30.dylib`system_writev + 41
    frame #2: 0x0000000101e3d1ba libgnutls.30.dylib`_gnutls_io_write_flush + 428
    frame #3: 0x0000000101e37689 libgnutls.30.dylib`_gnutls_send_tlen_int + 1222
    frame #4: 0x0000000101e5b78a libgnutls.30.dylib`gnutls_alert_send + 124
    frame #5: 0x0000000101e36f4f libgnutls.30.dylib`gnutls_bye + 86
    frame #6: 0x0000000101e1e8bc msmtp`tls_close([...]) + 28 at tls.c:1736 [opt]
    frame #7: 0x0000000101e1c382 msmtp`smtp_close([...]) + 34 at smtp.c:1905 [opt]
    frame #8: 0x0000000101e136ab msmtp`msmtp_sendmail [inlined] msmtp_endsession([...]) + 53 at msmtp.c:555 [opt]
    frame #9: 0x0000000101e13676 msmtp`msmtp_sendmail([...]) + 1558 at msmtp.c:1913 [opt]
    frame #10: 0x0000000101e183e6 msmtp`main([...]) + 5094 at msmtp.c:4157 [opt]
    frame #11: 0x00007fffd5b1e255 libdyld.dylib`start + 1
(lldb) c
Process 70391 resuming
Process 70391 exited with status = 0 (0x00000000) Terminated due to signal 13

This has nothing to do with git, I probably didn't realize before because I guess mutt ignores this completely. I already sent a patch upstream.

Roger.

← back to recent threads