fix: handle closed connection access to prevent runtime error

This commit is contained in:
2025-02-08 18:33:43 +07:00
parent bb6e4e2568
commit af6c6ba8a6
2 changed files with 8 additions and 0 deletions

View File

@ -2,11 +2,14 @@ package session
import (
"fmt"
"github.com/google/uuid"
"golang.org/x/crypto/ssh"
"net"
)
type Session struct {
ID uuid.UUID
Slug string
ConnChannels []ssh.Channel
Connection *ssh.ServerConn
GlobalRequest <-chan *ssh.Request
@ -33,6 +36,8 @@ func init() {
func New(conn *ssh.ServerConn, sshChannel <-chan ssh.NewChannel, req <-chan *ssh.Request) *Session {
session := &Session{
ID: uuid.New(),
Slug: "",
ConnChannels: []ssh.Channel{},
Connection: conn,
GlobalRequest: req,
@ -53,6 +58,8 @@ func (session *Session) Close() {
session.Done <- true
if session.TunnelType != HTTP {
session.Listener.Close()
} else {
delete(Clients, session.Slug)
}
for _, ch := range session.ConnChannels {