Skip to content

Commit b258ee9

Browse files
ssh: fix race condition in HandleRequests() method
1 parent 34f9078 commit b258ee9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

ssh/server/handler/sftp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func connectSFTP(ctx context.Context, client gliderssh.Session, sess *session.Se
108108
return err
109109
}
110110

111-
go session.HandleRequests(ctx, reqs, api)
111+
go session.HandleRequests(ctx, reqs, api, ctx.Done())
112112

113113
if errs := api.SessionAsAuthenticated(sess.UID); len(errs) > 0 {
114114
return errs[0]

ssh/server/handler/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func connectSSH(ctx context.Context, client gliderssh.Session, sess *session.Ses
187187

188188
defer agent.Close()
189189

190-
go session.HandleRequests(ctx, reqs, api)
190+
go session.HandleRequests(ctx, reqs, api, ctx.Done())
191191

192192
metadata.MaybeStoreEstablished(ctx.(gliderssh.Context), true)
193193

ssh/session/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func loadEnv(env []string) map[string]string {
259259
return m
260260
}
261261

262-
func HandleRequests(ctx context.Context, reqs <-chan *gossh.Request, c internalclient.Client) {
262+
func HandleRequests(ctx context.Context, reqs <-chan *gossh.Request, c internalclient.Client, done <-chan struct{}) {
263263
for {
264264
select {
265265
case req := <-reqs:
@@ -285,7 +285,7 @@ func HandleRequests(ctx context.Context, reqs <-chan *gossh.Request, c internalc
285285
}
286286
}
287287
}
288-
case <-ctx.Done():
288+
case <-done:
289289
return
290290
}
291291
}

0 commit comments

Comments
 (0)