Skip to content

Commit

Permalink
Merge pull request #131 from mendersoftware/cherry-2.2.x-MEN-6888-fix…
Browse files Browse the repository at this point in the history
…-ping-pong

[Cherry 2.2.x]: MEN-6888: Stop shell after health check fails
  • Loading branch information
lluiscampos committed Jan 31, 2024
2 parents aa51cd6 + 2b99d7f commit a796c86
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions session/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ func MenderShellSessionsGetByUserId(userId string) []*MenderShellSession {
}
}

func MenderShellStopById(sessionId string) error {
s := MenderShellSessionGetById(sessionId)
if s.shell == nil {
return ErrSessionNotFound
}
e := s.StopShell()
if e != nil && procps.ProcessExists(s.shellPid) {
return e
}
return MenderShellDeleteById(sessionId)
}

func MenderShellStopByUserId(userId string) (count uint, err error) {
a := sessionsByUserIdMap[userId]
log.Debugf("stopping all shells of user %s.", userId)
Expand Down Expand Up @@ -396,6 +408,12 @@ func (s *MenderShellSession) healthcheck() {
if s.healthcheckTimeout.Before(time.Now()) {
log.Errorf("session %s, health check failed, connection with the client lost", s.id)
s.expiresAt = time.Now()
err := MenderShellStopById(s.id)
if err != nil {
log.Errorf("session %s, error stopping shell %s", s.id, err.Error())
} else {
log.Infof("session %s successfully stopped", s.id)
}
return
}
case <-time.After(time.Until(nextHealthcheckPing)):
Expand Down

0 comments on commit a796c86

Please sign in to comment.