mirror of
https://github.com/screego/server.git
synced 2026-04-22 15:37:21 +08:00
fix: limit /health timeout to 5 seconds
This commit is contained in:
+4
-3
@@ -111,17 +111,18 @@ func (r *Rooms) Start() {
|
||||
}
|
||||
|
||||
func (r *Rooms) Count() (int, string) {
|
||||
timeout := time.After(5 * time.Second)
|
||||
|
||||
h := Health{Response: make(chan int, 1)}
|
||||
select {
|
||||
case r.Incoming <- ClientMessage{SkipConnectedCheck: true, Incoming: &h}:
|
||||
case <-time.After(5 * time.Second):
|
||||
case <-timeout:
|
||||
return -1, "main loop didn't accept a message within 5 second"
|
||||
}
|
||||
r.Incoming <- ClientMessage{SkipConnectedCheck: true, Incoming: &h}
|
||||
select {
|
||||
case count := <-h.Response:
|
||||
return count, ""
|
||||
case <-time.After(5 * time.Second):
|
||||
case <-timeout:
|
||||
return -1, "main loop didn't respond to a message within 5 second"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user