watermill icon indicating copy to clipboard operation
watermill copied to clipboard

Router persists in running state after closing it

Open mjjs opened this issue 2 years ago • 3 comments

What happened: Running router.Run after router.Close returns an error router is already running.

Apparently the router's internal state router.isRunning persists in true state even after the call to router.Close.

This causes any router.Run call after close to fail due to this check.

What did you expect to happen: The router should start.

How to reproduce: Here is a minimal way to reproduce this: https://github.com/mjjs/watermill-close-bugreport It is copied from the basic router example and I added code in the end to stop and re-start the router + verify the state.

Just clone it and run go run . in the root.

Output:

[watermill] 2022/09/20 17:30:07.041181 router.go:251: 	level=INFO  msg="Adding handler" handler_name=struct_handler topic=incoming_messages_topic 
[watermill] 2022/09/20 17:30:07.041235 router.go:251: 	level=INFO  msg="Adding handler" handler_name=print_outgoing_messages topic=outgoing_messages_topic 
[watermill] 2022/09/20 17:30:07.041279 router.go:549: 	level=INFO  msg="Starting handler" subscriber_name=struct_handler topic=incoming_messages_topic 
[watermill] 2022/09/20 17:30:07.041288 router.go:549: 	level=INFO  msg="Starting handler" subscriber_name=print_outgoing_messages topic=outgoing_messages_topic 
router.IsRunning after run: true
router.Running after run: true
[watermill] 2022/09/20 17:30:10.042502 router.go:501: 	level=INFO  msg="Closing router" 
[watermill] 2022/09/20 17:30:10.042541 router.go:361: 	level=INFO  msg="Waiting for messages" timeout=30s 
[watermill] 2022/09/20 17:30:10.042588 pubsub.go:307: 	level=INFO  msg="Pub/Sub closed" pubsub_uuid=43KcqrN5heuZAYvXJfhDfH 
[watermill] 2022/09/20 17:30:10.042606 router.go:423: 	level=INFO  msg="Subscriber stopped" subscriber_name=print_outgoing_messages topic=outgoing_messages_topic 
[watermill] 2022/09/20 17:30:10.042613 router.go:512: 	level=INFO  msg="Router closed" 
router.IsRunning after close: true
router.Running after close: true
panic: router is already running

goroutine 1 [running]:
main.main()
	/home/x/dev/watermill-close-bugreport/main.go:93 +0x3c5
exit status 2

mjjs avatar Sep 20 '22 14:09 mjjs

any news about it?? any advice or tip @checkmunza??

Kortivex avatar Oct 17 '22 14:10 Kortivex

Have the same behaviour on my project. I'm trying to check if my RabbitMQ connection is down, but it always return a true even when I shutdown the RabbitMQ server by hand.

Yoleop avatar Oct 20 '22 11:10 Yoleop

Hey, thanks for reporting the issue.

As much as the name is confusing, the initial design idea was to have a way to check if the Router is already up. Perhaps it should be called "started" instead of "running".

We could rework this somehow to allow re-running of the Router, but it wasn't designed for it then. Similarly like you don't restart an HTTP server.

Can you describe your use cases? "trying to check if my RabbitMQ connection is down" seems like something unrelated to the Router.

m110 avatar Jan 02 '23 09:01 m110