summaryrefslogtreecommitdiff
path: root/internal/sshd/connection.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/sshd/connection.go')
-rw-r--r--internal/sshd/connection.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go
index c8d1456..a9b9e97 100644
--- a/internal/sshd/connection.go
+++ b/internal/sshd/connection.go
@@ -50,14 +50,16 @@ var (
type connection struct {
begin time.Time
concurrentSessions *semaphore.Weighted
+ remoteAddr string
}
type channelHandler func(context.Context, ssh.Channel, <-chan *ssh.Request)
-func newConnection(maxSessions int64) *connection {
+func newConnection(maxSessions int64, remoteAddr string) *connection {
return &connection{
begin: time.Now(),
concurrentSessions: semaphore.NewWeighted(maxSessions),
+ remoteAddr: remoteAddr,
}
}
@@ -83,6 +85,14 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
go func() {
defer c.concurrentSessions.Release(1)
+
+ // Prevent a panic in a single session from taking out the whole server
+ defer func() {
+ if err := recover(); err != nil {
+ log.Warnf("panic handling session from %s: recovered: %#+v", c.remoteAddr, err)
+ }
+ }()
+
handler(ctx, channel, requests)
}()
}