Disconnect from firehoses in parallel when shutting down
parent
1358bc3f08
commit
ecf2fc57d8
|
@ -14,6 +14,7 @@ import (
|
|||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -153,11 +154,17 @@ func runConsumers(ctx context.Context, db *gorm.DB, doneCh chan struct{}) {
|
|||
}
|
||||
|
||||
case <-ctx.Done():
|
||||
var wg sync.WaitGroup
|
||||
for host, handle := range running {
|
||||
handle.cancel()
|
||||
_ = handle.consumer.Wait(ctx)
|
||||
wg.Add(1)
|
||||
go func(handle consumerHandle) {
|
||||
handle.cancel()
|
||||
_ = handle.consumer.Wait(ctx)
|
||||
wg.Done()
|
||||
}(handle)
|
||||
delete(running, host)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
case v := <-ticker.C:
|
||||
// Non-blocking send.
|
||||
|
|
Loading…
Reference in New Issue