summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2022-05-09 20:41:17 +0400
committerIgor Drozdov <idrozdov@gitlab.com>2022-05-09 20:42:33 +0400
commitd9c008f8ac20f9494ec72c4cfc7c847516c1dbff (patch)
tree5006484d63e07053f4ac61c79ed44bd6bab2cdee
parent199ea1d17a2497c34cb820728cdbc01fb5e700e5 (diff)
downloadgitlab-shell-id-accept-single-session.tar.gz
Sync sessions and new channels executionid-accept-single-session
If the connection stops accepting new channels we want to wait until Gitaly operation is complete before exiting
-rw-r--r--internal/sshd/connection.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go
index 1312833..19dc85a 100644
--- a/internal/sshd/connection.go
+++ b/internal/sshd/connection.go
@@ -5,6 +5,7 @@ import (
"golang.org/x/crypto/ssh"
"golang.org/x/sync/semaphore"
+ "sync"
"gitlab.com/gitlab-org/gitlab-shell/internal/metrics"
@@ -28,6 +29,7 @@ func newConnection(maxSessions int64, remoteAddr string) *connection {
func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, handler channelHandler) {
ctxlog := log.WithContextFields(ctx, log.Fields{"remote_addr": c.remoteAddr})
+ var wg sync.WaitGroup
for newChannel := range chans {
ctxlog.WithField("channel_type", newChannel.ChannelType()).Info("connection: handle: new channel requested")
if newChannel.ChannelType() != "session" {
@@ -48,8 +50,10 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
continue
}
+ wg.Add(1)
go func() {
defer c.concurrentSessions.Release(1)
+ defer wg.Done()
// Prevent a panic in a single session from taking out the whole server
defer func() {
@@ -62,4 +66,5 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
ctxlog.Info("connection: handle: done")
}()
}
+ wg.Wait()
}