watermill
watermill copied to clipboard
Router does not wait for running handlers to complete.
I can't find anywhere that the Router
will call Wait
method on runningHandlersWg
.
type Router struct {
...
handlersWg *sync.WaitGroup
runningHandlersWg *sync.WaitGroup
...
}
Should it need to do that so we can close the router gracefully?
// Close gracefully closes the router with a timeout provided in the configuration.
func (r *Router) Close() error {
r.closedLock.Lock()
defer r.closedLock.Unlock()
if r.closed {
return nil
}
r.closed = true
r.logger.Info("Closing router", nil)
defer r.logger.Info("Router closed", nil)
close(r.closeCh)
defer close(r.closedCh)
timeouted := sync_internal.WaitGroupTimeout(r.handlersWg, r.config.CloseTimeout)
if timeouted {
return errors.New("router close timeouted")
}
return nil
}
Yeah I guess I am also facing a similar issue. When I shutdown my program I get this error message that says
level=ERROR msg="All handlers stopped, closing router" err="all router handlers stopped"
It also do not see any of the examples calling the Close()
method on the router.
Fixed here: https://github.com/ThreeDotsLabs/watermill/pull/304