Skip to content

Commit b455a04

Browse files
authored
chore: check redis closed. (#2)
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 6c514c4 commit b455a04

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

redis.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ func (s *Worker) Shutdown() error {
205205
}
206206

207207
s.stopOnce.Do(func() {
208-
close(s.stop)
209208
s.pubsub.Close()
210209
s.rdb.Close()
210+
close(s.stop)
211211
})
212212
return nil
213213
}
@@ -244,7 +244,7 @@ func (s *Worker) Run() error {
244244
// check queue status
245245
select {
246246
case <-s.stop:
247-
return queue.ErrQueueShutdown
247+
return nil
248248
default:
249249
}
250250

@@ -263,6 +263,13 @@ func (s *Worker) Run() error {
263263
}
264264

265265
for {
266+
// check queue status
267+
select {
268+
case <-s.stop:
269+
return nil
270+
default:
271+
}
272+
266273
select {
267274
case m, ok := <-ch:
268275
select {

redis_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ func TestGoroutineLeak(t *testing.T) {
251251
m.Message = fmt.Sprintf("foobar: %d", i+1)
252252
assert.NoError(t, q.Queue(m))
253253
}
254-
time.Sleep(2 * time.Second)
254+
time.Sleep(1 * time.Second)
255255
q.Shutdown()
256256
q.Wait()
257-
time.Sleep(2 * time.Second)
257+
time.Sleep(1 * time.Second)
258258
fmt.Println("number of goroutines:", runtime.NumGoroutine())
259259
}
260260

0 commit comments

Comments
 (0)