-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make DefaultOptions a function that produces new Options on every call #308
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of this change, but it will require a major version bump since this would be a breaking change.
To mitigate the compatibility issue, we could keep the |
@kozlovic I don't think you can have a |
Another idea maybe, how about deprecating the fields which are pointers as part of |
How about NewDefaultOptions(), and keep the struct the same. |
or |
@wallyqs, it does not feel like a good idea to me. You can't guarantee that all fields are primitive and do not contain any pointers. Personally I think it's better to drop deprecated API faster while bumping major version. Otherwise it will become a big mess where no one understands how it works (or will just keep going without fixing their code). |
@nogoegst but |
@wallyqs |
@@ -79,18 +79,21 @@ var ( | |||
ErrStaleConnection = errors.New("nats: " + STALE_CONNECTION) | |||
) | |||
|
|||
var DefaultOptions = Options{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nogoegst I am torn. Although I fully agree with you that using DefaultOptions
as a struct may lead to errors, especially with the presence of pointers (there is already one, and others may be added in the future), making this change would break potentially lots of users (arguably, they should vendor if they are concerned about breaking changes). The worse, is that the use of DefaultOptions
was safe until 1.2.2, where the pointer was added.
Leaving DefaultOptions
and adding GetDefaultOptions()
would avoid breaking users' existing code base. I was thinking that we could remove the Dialer
from DefaultOptions
structure, add a comment that DefaultOptions
is deprecated and users should use GetDefaultOptions()
instead, and make sure that nothing is ever added to DefaultOptions
structure itself, but instead in GetDefaultOptions()
.
Removing the Dialer
from DefaultOptions
is not going to break users (the ones at 1.2.2) since the Connect()
call is using the exact same net.Dialer
with DefaultTimeout
if no Dialer
is set in Options
.
I can do all these changes myself, but I wanted to give you the opportunity to discuss or implement those changes since you have originally submitted the PR. Let me know how you want to proceed.
on every call. Deprecate DefaultOptions.
29c0ba3
to
12ef716
Compare
@kozlovic agreed. Fixed by renaming to |
Thanks for your contribution! |
DEPRECATED: Use GetDefaultOptions() instead. DefaultOptions is not safe for use by multiple clients. For details see nats-io/nats.go#308. DefaultOptions are the NATS Streaming client's default options Signed-off-by: anxinyf <[email protected]>
At the moment DefaultOptions is a global struct that is being copied by value. Some of the fields are pointers, so they got copied as well while retaining their value and thus making these fields effectively global. This breaks logic of multiple operations with DefaultOptions which may be modified by other users (e.g. in tests).
This PR is making it a function that returns a fresh copy of DefaultOptions each time to use independently.