watermill icon indicating copy to clipboard operation
watermill copied to clipboard

Router does not wait for running handlers to complete.

Open checkmunza opened this issue 2 years ago • 1 comments

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
}

checkmunza avatar Jul 31 '21 17:07 checkmunza

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.

anandsunderraman avatar Apr 08 '22 17:04 anandsunderraman

Fixed here: https://github.com/ThreeDotsLabs/watermill/pull/304

roblaszczak avatar Jan 21 '23 16:01 roblaszczak