Closed robinkb closed 5 months ago
Since NewServer()
takes a pointer to the struct you simply cant be sure it wont be modified. So do not reuse it.
Make new ones or deep copy a template one
Fair. Does it make sense to add documentation? As you said, the fact that NewServer()
takes a pointer already heavily implies that you shouldn't reuse. If not, I would just close the issue.
I am sure more documentation on these functions can only help :) Be great if you sent a PR
Observed behavior
I am starting embedded NATS Servers. If I reuse the same Options struct to initialize them (with NewServer) and to configure them at runtime (with ReloadOptions), I get strange behavior from the server. See the snippet below:
This results in the following logs:
If I clone the Options before passing them to NewServer and Server.ReloadOptions, it works as expected. JetStream is enabled and forms a cluster successfully.
So for example in the snippet, on line 13, I change
s1opts
tos1opts.Clone()
, and so on.Expected behavior
It was suggested to me in Slack that having to call
Clone()
to pass the Options is not expected behavior.Server and client version
NATS Server v2.10/11
Host environment
Linux, AMD64
Steps to reproduce
See snippet above.