Skip to content

Commit

Permalink
fix: Error on session <session_id>: EOF using port forwarding
Browse files Browse the repository at this point in the history
Regression introduced with 51d8669

New go routine should only check `SessionStatusActive` to kill the session (initiated by a `user kick` or `user ban` for example)
  • Loading branch information
libvoid committed Sep 20, 2023
1 parent 37a300e commit 9d44c0f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/bastion/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,21 @@ func ChannelHandler(srv *ssh.Server, conn *gossh.ServerConn, newChan gossh.NewCh
_ = ch.Close()
return
}
go func(_ *gossh.ServerConn, dbConn *gorm.DB, sessionID uint) {
go func(_ *gossh.ServerConn, sessionID uint) {
for {
sess := dbmodels.Session{Model: gorm.Model{ID: sessionID}, Status: string(dbmodels.SessionStatusActive)}
if err := dbConn.First(&sess).Error; err != nil || sess.Status != string(dbmodels.SessionStatusActive) {
log.Println("Session should be closed", sessionID, "closing connection")
sess := dbmodels.Session{
Model: gorm.Model{ID: sessionID},
Status: string(dbmodels.SessionStatusActive),
}

if sess.Status != string(dbmodels.SessionStatusActive) {
log.Println("Session", sessionID, "should be closed : closing connection")
conn.Close()
break
}
time.Sleep(30 * time.Second) // TODO: VDO: make configurable
time.Sleep(60 * time.Second)
}
}(conn, actx.db, sess.ID)
}(conn, sess.ID)
go func() {
err = multiChannelHandler(conn, newChan, ctx, sessionConfigs, sess.ID)
if err != nil {
Expand Down

0 comments on commit 9d44c0f

Please sign in to comment.