Skip to content

Commit 693c6f8

Browse files
committed
ssh/connection.go: fix and enhance trace logs
In commit 326b1ee of PR git-lfs#5063 we added trace logging to several functions and methods related to the creation and termination of SSH sessions in order to help analyze the diagnostic logs generated when transferring Git LFS objects over SSH. However, in the startConnection() function in our ssh/connection.go source file, we report the successful creation of a session even if we are returning a non-nil error value. Therefore we revise our trace logging in that function to distinguish between unsuccessful and successful conditions based on whether the PktlineConnection structure's Start() method returned an error or not. In addition, we also update a number of our other trace log messages to include the relevant session ID. (Note that we refer to SSH sessions as "connections" in our code, although in practice they may share a single SSH connection using a control socket.) Because we maintain a set of SSH sessions and do not necessarily start or terminate all of them at the same time, this change will provide more clarity as to the state of each individual session at different points in a trace log. Finally, we rephrase several trace log messages generated by the setConnectionCount() method of the SSHTransfer structure so they more fully explain when the method is terminating specific sessions because it has been asked to reduce the total number of sessions.
1 parent 3bad67e commit 693c6f8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ssh/connection.go

Lines changed: 10 additions & 8 deletions
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) (resetting total from %d to %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) (resetting total from %d to %d)", tn+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) (resetting total from %d to %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)