Skip to content

Commit 40ad444

Browse files
committed
fix: limit /health timeout to 5 seconds
1 parent bcf590f commit 40ad444

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎ws/rooms.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,18 @@ func (r *Rooms) Start() {
111111
}
112112

113113
func (r *Rooms) Count() (int, string) {
114+
timeout := time.After(5 * time.Second)
115+
114116
h := Health{Response: make(chan int, 1)}
115117
select {
116118
case r.Incoming <- ClientMessage{SkipConnectedCheck: true, Incoming: &h}:
117-
case <-time.After(5 * time.Second):
119+
case <-timeout:
118120
return -1, "main loop didn't accept a message within 5 second"
119121
}
120-
r.Incoming <- ClientMessage{SkipConnectedCheck: true, Incoming: &h}
121122
select {
122123
case count := <-h.Response:
123124
return count, ""
124-
case <-time.After(5 * time.Second):
125+
case <-timeout:
125126
return -1, "main loop didn't respond to a message within 5 second"
126127
}
127128
}

0 commit comments

Comments
 (0)