Skip to content

Commit

Permalink
Avoid panic when querying the stats monitor before service start (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben authored Oct 31, 2023
1 parent bef5bf6 commit cccb7f9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ type Monitor struct {

pendingCPUs atomic.Float64

started core.Fuse
shutdown core.Fuse
}

func NewMonitor() *Monitor {
return &Monitor{
started: core.NewFuse(),
shutdown: core.NewFuse(),
}
}
Expand Down Expand Up @@ -96,6 +98,8 @@ func (m *Monitor) Start(conf *config.Config) error {

prometheus.MustRegister(m.promCPULoad, m.promNodeAvailable, m.requestGauge)

m.started.Break()

return nil
}

Expand Down Expand Up @@ -189,15 +193,15 @@ func (m *Monitor) GetCPULoad() float64 {
}

func (m *Monitor) CanAccept() bool {
if m.shutdown.IsBroken() {
if !m.started.IsBroken() || m.shutdown.IsBroken() {
return false
}

return m.getAvailable() > m.maxCost
}

func (m *Monitor) canAcceptIngress(info *livekit.IngressInfo) (bool, float64, float64) {
if m.shutdown.IsBroken() {
if !m.started.IsBroken() || m.shutdown.IsBroken() {
return false, 0, 0
}

Expand Down

0 comments on commit cccb7f9

Please sign in to comment.