Skip to content

Commit e6a901e

Browse files
committed
cmd/go: disable SSH connection pooling to avoid git hang
Fixes #13453. Fixes #16104. Change-Id: I4e94f606df786af8143f8649c9afde570f346301 Reviewed-on: https://go-review.googlesource.com/31353 Reviewed-by: Quentin Smith <[email protected]>
1 parent e05d014 commit e6a901e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/cmd/go/get.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ func runGet(cmd *Command, args []string) {
9898
os.Setenv("GIT_TERMINAL_PROMPT", "0")
9999
}
100100

101+
// Disable any ssh connection pooling by Git.
102+
// If a Git subprocess forks a child into the background to cache a new connection,
103+
// that child keeps stdout/stderr open. After the Git subprocess exits,
104+
// os /exec expects to be able to read from the stdout/stderr pipe
105+
// until EOF to get all the data that the Git subprocess wrote before exiting.
106+
// The EOF doesn't come until the child exits too, because the child
107+
// is holding the write end of the pipe.
108+
// This is unfortunate, but it has come up at least twice
109+
// (see golang.org/issue/13453 and golang.org/issue/16104)
110+
// and confuses users when it does.
111+
// If the user has explicitly set GIT_SSH or GIT_SSH_COMMAND,
112+
// assume they know what they are doing and don't step on it.
113+
// But default to turning off ControlMaster.
114+
if os.Getenv("GIT_SSH") == "" && os.Getenv("GIT_SSH_COMMAND") == "" {
115+
os.Setenv("GIT_SSH_COMMAND", "ssh -o ControlMaster=no")
116+
}
117+
101118
// Phase 1. Download/update.
102119
var stk importStack
103120
mode := 0

0 commit comments

Comments
 (0)