fix: handle closed connection access to prevent runtime error
This commit is contained in:
@ -56,6 +56,7 @@ func (s *Session) handleGlobalRequest() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
Clients[slug] = s
|
Clients[slug] = s
|
||||||
|
s.Slug = slug
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
binary.Write(buf, binary.BigEndian, uint32(portToBind))
|
binary.Write(buf, binary.BigEndian, uint32(portToBind))
|
||||||
log.Printf("Forwarding approved on port: %d", portToBind)
|
log.Printf("Forwarding approved on port: %d", portToBind)
|
||||||
|
|||||||
@ -2,11 +2,14 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
Slug string
|
||||||
ConnChannels []ssh.Channel
|
ConnChannels []ssh.Channel
|
||||||
Connection *ssh.ServerConn
|
Connection *ssh.ServerConn
|
||||||
GlobalRequest <-chan *ssh.Request
|
GlobalRequest <-chan *ssh.Request
|
||||||
@ -33,6 +36,8 @@ func init() {
|
|||||||
|
|
||||||
func New(conn *ssh.ServerConn, sshChannel <-chan ssh.NewChannel, req <-chan *ssh.Request) *Session {
|
func New(conn *ssh.ServerConn, sshChannel <-chan ssh.NewChannel, req <-chan *ssh.Request) *Session {
|
||||||
session := &Session{
|
session := &Session{
|
||||||
|
ID: uuid.New(),
|
||||||
|
Slug: "",
|
||||||
ConnChannels: []ssh.Channel{},
|
ConnChannels: []ssh.Channel{},
|
||||||
Connection: conn,
|
Connection: conn,
|
||||||
GlobalRequest: req,
|
GlobalRequest: req,
|
||||||
@ -53,6 +58,8 @@ func (session *Session) Close() {
|
|||||||
session.Done <- true
|
session.Done <- true
|
||||||
if session.TunnelType != HTTP {
|
if session.TunnelType != HTTP {
|
||||||
session.Listener.Close()
|
session.Listener.Close()
|
||||||
|
} else {
|
||||||
|
delete(Clients, session.Slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ch := range session.ConnChannels {
|
for _, ch := range session.ConnChannels {
|
||||||
|
|||||||
Reference in New Issue
Block a user