Skip to content

Commit

Permalink
Only decrement server_interactive_sessions_total once per session
Browse files Browse the repository at this point in the history
`session.Close` can get called multiple times, from different deferred
cleanups. The associated metric decrement should only happen on the
first call, to map 1:1 with increments.
Without this, we could end up with negative
`server_interactive_sessions_total` counts.

Fixes #3755
  • Loading branch information
Andrew Lytvynov authored and awly committed Aug 19, 2020
1 parent e559509 commit 1d63421
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/srv/sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
var (
serverSessions = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "server_interactive_sessions_total",
Name: teleport.MetricServerInteractiveSessions,
Help: "Number of active sessions",
},
)
Expand Down Expand Up @@ -563,8 +563,8 @@ func (s *session) PID() int {

// Close ends the active session forcing all clients to disconnect and freeing all resources
func (s *session) Close() error {
serverSessions.Dec()
s.closeOnce.Do(func() {
serverSessions.Dec()
// closing needs to happen asynchronously because the last client
// (session writer) will try to close this session, causing a deadlock
// because of closeOnce
Expand Down

0 comments on commit 1d63421

Please sign in to comment.