I spent some time setting up a test environment with nats and I ran into an issue with the use of defer with runtime.Goexit(). The example code in
https://github.com/nats-io/nats/blob/master/examples/nats-sub.go does not use defer to close the connection, but the code examples in
https://github.com/nats-io/nats/blob/master/README.md do, so if you are naive like me and put the two together, the connection on the subscriber end is always closed by the defer when runtime.Goexit() is called.
Anyhow, I just wanted to call this out so in case someone else runs into the same issue they are aware of what's going on. Here is the documentation for runtime.Goexit():
One simple fix might be to remove the deferred connection close from the README documentation to avoid confusion.
Sincerely,
Anthony Eden