@@ -42,7 +42,7 @@ func NewSSHTransfer(osEnv config.Environment, gitEnv config.Environment, meta *S
42
42
}
43
43
44
44
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 )
46
46
var errbuf bytes.Buffer
47
47
exe , args , multiplexing , controlPath := GetLFSExeAndArgs (osEnv , gitEnv , meta , "git-lfs-transfer" , operation , true , multiplexControlPath )
48
48
cmd , err := subprocess .ExecCommand (exe , args ... )
@@ -81,125 +81,128 @@ func startConnection(id int, osEnv config.Environment, gitEnv config.Environment
81
81
w .Close ()
82
82
cmd .Wait ()
83
83
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 )
84
87
}
85
- tracerx .Printf ("pure SSH connection successful" )
86
88
return conn , multiplexing , controlPath , err
87
89
}
88
90
89
91
// Connection returns the nth connection (starting from 0) in this transfer
90
92
// instance or nil if there is no such item.
91
- func (tr * SSHTransfer ) IsMultiplexingEnabled () bool {
92
- return tr .multiplexing
93
+ func (st * SSHTransfer ) IsMultiplexingEnabled () bool {
94
+ return st .multiplexing
93
95
}
94
96
95
97
// Connection returns the nth connection (starting from 0) in this transfer
96
98
// instance if it is initialized and otherwise initializes a new connection and
97
- // saves it in the nth position. In all cases, nil is returned if n is greater
98
- // than the maximum number of connections.
99
- func (tr * SSHTransfer ) Connection (n int ) (* PktlineConnection , error ) {
100
- tr .lock .RLock ()
101
- if n >= len (tr .conn ) {
102
- tr .lock .RUnlock ()
103
- return nil , nil
104
- }
105
- if tr .conn [n ] != nil {
106
- defer tr .lock .RUnlock ()
107
- return tr .conn [n ], nil
108
- }
109
- tr .lock .RUnlock ()
99
+ // saves it in the nth position. In all cases, nil is returned with an error
100
+ // if n is greater than the maximum number of connections, including when
101
+ // the connection array itself is nil.
102
+ func (st * SSHTransfer ) Connection (n int ) (* PktlineConnection , error ) {
103
+ st .lock .RLock ()
104
+ if n >= len (st .conn ) {
105
+ st .lock .RUnlock ()
106
+ return nil , errors .New (tr .Tr .Get ("pure SSH connection unavailable (#%d)" , n ))
107
+ }
108
+ if st .conn [n ] != nil {
109
+ defer st .lock .RUnlock ()
110
+ return st .conn [n ], nil
111
+ }
112
+ st .lock .RUnlock ()
110
113
111
- tr .lock .Lock ()
112
- defer tr .lock .Unlock ()
113
- if tr .conn [n ] != nil {
114
- return tr .conn [n ], nil
114
+ st .lock .Lock ()
115
+ defer st .lock .Unlock ()
116
+ if st .conn [n ] != nil {
117
+ return st .conn [n ], nil
115
118
}
116
- conn , _ , err := tr .spawnConnection (n )
119
+ conn , _ , err := st .spawnConnection (n )
117
120
if err != nil {
118
121
return nil , err
119
122
}
120
- tr .conn [n ] = conn
123
+ st .conn [n ] = conn
121
124
return conn , nil
122
125
}
123
126
124
127
// ConnectionCount returns the number of connections this object has.
125
- func (tr * SSHTransfer ) ConnectionCount () int {
126
- tr .lock .RLock ()
127
- defer tr .lock .RUnlock ()
128
- return len (tr .conn )
128
+ func (st * SSHTransfer ) ConnectionCount () int {
129
+ st .lock .RLock ()
130
+ defer st .lock .RUnlock ()
131
+ return len (st .conn )
129
132
}
130
133
131
134
// SetConnectionCount sets the number of connections to the specified number.
132
- func (tr * SSHTransfer ) SetConnectionCount (n int ) error {
133
- tr .lock .Lock ()
134
- defer tr .lock .Unlock ()
135
- return tr .setConnectionCount (n )
135
+ func (st * SSHTransfer ) SetConnectionCount (n int ) error {
136
+ st .lock .Lock ()
137
+ defer st .lock .Unlock ()
138
+ return st .setConnectionCount (n )
136
139
}
137
140
138
141
// SetConnectionCountAtLeast sets the number of connections to be not less than
139
142
// the specified number.
140
- func (tr * SSHTransfer ) SetConnectionCountAtLeast (n int ) error {
141
- tr .lock .Lock ()
142
- defer tr .lock .Unlock ()
143
- count := len (tr .conn )
143
+ func (st * SSHTransfer ) SetConnectionCountAtLeast (n int ) error {
144
+ st .lock .Lock ()
145
+ defer st .lock .Unlock ()
146
+ count := len (st .conn )
144
147
if n <= count {
145
148
return nil
146
149
}
147
- return tr .setConnectionCount (n )
150
+ return st .setConnectionCount (n )
148
151
}
149
152
150
- func (tr * SSHTransfer ) spawnConnection (n int ) (* PktlineConnection , string , error ) {
151
- conn , _ , controlPath , err := startConnection (n , tr .osEnv , tr .gitEnv , tr .meta , tr .operation , tr .controlPath )
153
+ func (st * SSHTransfer ) spawnConnection (n int ) (* PktlineConnection , string , error ) {
154
+ conn , _ , controlPath , err := startConnection (n , st .osEnv , st .gitEnv , st .meta , st .operation , st .controlPath )
152
155
if err != nil {
153
- tracerx .Printf ("failed to spawn pure SSH connection: %s" , err )
156
+ tracerx .Printf ("failed to spawn pure SSH connection (#%d) : %s" , n , err )
154
157
return nil , "" , err
155
158
}
156
159
return conn , controlPath , err
157
160
}
158
161
159
- func (tr * SSHTransfer ) setConnectionCount (n int ) error {
160
- count := len (tr .conn )
162
+ func (st * SSHTransfer ) setConnectionCount (n int ) error {
163
+ count := len (st .conn )
161
164
if n < count {
162
165
tn := n
163
166
if tn == 0 {
164
167
tn = 1
165
168
}
166
- for _ , item := range tr .conn [tn :count ] {
169
+ for i , item := range st .conn [tn :count ] {
167
170
if item == nil {
168
- tracerx .Printf ("skipping uninitialized lazy pure SSH connection (%d -> %d)" , count , n )
171
+ tracerx .Printf ("skipping uninitialized lazy pure SSH connection (#%d) (resetting total from %d to %d)" , i , count , n )
169
172
continue
170
173
}
171
- tracerx .Printf ("terminating pure SSH connection (%d -> %d)" , count , n )
174
+ tracerx .Printf ("terminating pure SSH connection (#%d) (resetting total from %d to %d)" , tn + i , count , n )
172
175
if err := item .End (); err != nil {
173
176
return err
174
177
}
175
178
}
176
- tr .conn = tr .conn [0 :tn ]
179
+ st .conn = st .conn [0 :tn ]
177
180
} else if n > count {
178
181
for i := count ; i < n ; i ++ {
179
182
if i == 0 {
180
- conn , controlPath , err := tr .spawnConnection (i )
183
+ conn , controlPath , err := st .spawnConnection (i )
181
184
if err != nil {
182
185
return err
183
186
}
184
- tr .conn = append (tr .conn , conn )
185
- tr .controlPath = controlPath
187
+ st .conn = append (st .conn , conn )
188
+ st .controlPath = controlPath
186
189
} else {
187
- tr .conn = append (tr .conn , nil )
190
+ st .conn = append (st .conn , nil )
188
191
}
189
192
}
190
193
}
191
194
if n == 0 && count > 0 {
192
- tracerx .Printf ("terminating pure SSH connection (%d -> %d)" , count , n )
193
- if err := tr .conn [0 ].End (); err != nil {
195
+ tracerx .Printf ("terminating pure SSH connection (#0) (resetting total from %d to %d)" , count , n )
196
+ if err := st .conn [0 ].End (); err != nil {
194
197
return err
195
198
}
196
- tr .conn = nil
197
- tr .controlPath = ""
199
+ st .conn = nil
200
+ st .controlPath = ""
198
201
}
199
202
return nil
200
203
}
201
204
202
- func (tr * SSHTransfer ) Shutdown () error {
203
- tracerx .Printf ("shutting down pure SSH connection " )
204
- return tr .SetConnectionCount (0 )
205
+ func (st * SSHTransfer ) Shutdown () error {
206
+ tracerx .Printf ("shutting down pure SSH connections " )
207
+ return st .SetConnectionCount (0 )
205
208
}
0 commit comments