Skip to content

Commit 4b7e0aa

Browse files
committed
ssh/connection.go: fix and enhance trace logs
We added trace logging to several functions and methods related to the creation and shutdown of SSH connections in commit 326b1ee of PR git-lfs#5063, which help when debugging any problems with our implementation of the SSH-based object transfer protocol. However, in the startConnection() function in our ssh/connection.go source file, we report the successful creation of a connection even if we are returning a non-nil error value. Therefore we revise our trace logging there to distinguish unsuccessful and successful conditions, based on whether the PktlineConnection structure's Start() method returned an error or not. As well, we update a number of our other trace log message to include the connection ID. Because we maintain a set of SSH connections and do not necessarily start or shut down all of them at the same time, this change provides further clarity as to the state of each individual connection at different points in a trace log.
1 parent 4fb331b commit 4b7e0aa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ssh/connection.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewSSHTransfer(osEnv config.Environment, gitEnv config.Environment, meta *S
4242
}
4343

4444
func startConnection(id int, osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, operation string, multiplexControlPath string) (conn *PktlineConnection, multiplexing bool, controlPath string, err error) {
45-
tracerx.Printf("spawning pure SSH connection")
45+
tracerx.Printf("spawning pure SSH connection (%d)", id)
4646
var errbuf bytes.Buffer
4747
exe, args, multiplexing, controlPath := GetLFSExeAndArgs(osEnv, gitEnv, meta, "git-lfs-transfer", operation, true, multiplexControlPath)
4848
cmd, err := subprocess.ExecCommand(exe, args...)
@@ -81,8 +81,10 @@ func startConnection(id int, osEnv config.Environment, gitEnv config.Environment
8181
w.Close()
8282
cmd.Wait()
8383
err = errors.Combine([]error{err, fmt.Errorf(tr.Tr.Get("Failed to connect to remote SSH server: %s", cmd.Stderr))})
84+
tracerx.Printf("pure SSH connection unsuccessful (%d)", id)
85+
} else {
86+
tracerx.Printf("pure SSH connection successful (%d)", id)
8487
}
85-
tracerx.Printf("pure SSH connection successful")
8688
return conn, multiplexing, controlPath, err
8789
}
8890

@@ -150,7 +152,7 @@ func (tr *SSHTransfer) SetConnectionCountAtLeast(n int) error {
150152
func (tr *SSHTransfer) spawnConnection(n int) (*PktlineConnection, string, error) {
151153
conn, _, controlPath, err := startConnection(n, tr.osEnv, tr.gitEnv, tr.meta, tr.operation, tr.controlPath)
152154
if err != nil {
153-
tracerx.Printf("failed to spawn pure SSH connection: %s", err)
155+
tracerx.Printf("failed to spawn pure SSH connection (%d): %s", n, err)
154156
return nil, "", err
155157
}
156158
return conn, controlPath, err
@@ -163,12 +165,12 @@ func (tr *SSHTransfer) setConnectionCount(n int) error {
163165
if tn == 0 {
164166
tn = 1
165167
}
166-
for _, item := range tr.conn[tn:count] {
168+
for i, item := range tr.conn[tn:count] {
167169
if item == nil {
168-
tracerx.Printf("skipping uninitialized lazy pure SSH connection (%d -> %d)", count, n)
170+
tracerx.Printf("skipping uninitialized lazy pure SSH connection (%d) (%d -> %d)", i, count, n)
169171
continue
170172
}
171-
tracerx.Printf("terminating pure SSH connection (%d -> %d)", count, n)
173+
tracerx.Printf("terminating pure SSH connection (%d) (%d -> %d)", i, count, n)
172174
if err := item.End(); err != nil {
173175
return err
174176
}
@@ -189,7 +191,7 @@ func (tr *SSHTransfer) setConnectionCount(n int) error {
189191
}
190192
}
191193
if n == 0 && count > 0 {
192-
tracerx.Printf("terminating pure SSH connection (%d -> %d)", count, n)
194+
tracerx.Printf("terminating pure SSH connection (0) (%d -> %d)", count, n)
193195
if err := tr.conn[0].End(); err != nil {
194196
return err
195197
}
@@ -200,6 +202,6 @@ func (tr *SSHTransfer) setConnectionCount(n int) error {
200202
}
201203

202204
func (tr *SSHTransfer) Shutdown() error {
203-
tracerx.Printf("shutting down pure SSH connection")
205+
tracerx.Printf("shutting down pure SSH connections")
204206
return tr.SetConnectionCount(0)
205207
}

0 commit comments

Comments
 (0)