From fae29fbd5895363ef5464cc12029db85a1a24529 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 1 Mar 2019 15:33:49 +0100 Subject: git: fix goroutine block while pushing a remote On session.ReceivePack error the gororutine doing the encoding got blocked either writing objects to the pipe or sending error to the done channel. The problem did not cause a perceived problem but left blocked goroutines. Signed-off-by: Javi Fontan --- remote.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'remote.go') diff --git a/remote.go b/remote.go index de537ce..8060409 100644 --- a/remote.go +++ b/remote.go @@ -1020,7 +1020,12 @@ func pushHashes( if err != nil { return nil, err } - done := make(chan error) + + // Set buffer size to 1 so the error message can be written when + // ReceivePack fails. Otherwise the goroutine will be blocked writing + // to the channel. + done := make(chan error, 1) + go func() { e := packfile.NewEncoder(wr, s, useRefDeltas) if _, err := e.Encode(hs, config.Pack.Window); err != nil { @@ -1033,6 +1038,8 @@ func pushHashes( rs, err := sess.ReceivePack(ctx, req) if err != nil { + // close the pipe to unlock encode write + _ = rd.Close() return nil, err } -- cgit