-
Notifications
You must be signed in to change notification settings - Fork 173
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
Avoid panic when using dedicated client after being recycled, return an error instead #593
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hi @FZambia,
Many thanks! I originally planned to take care of this issue over the coming weekend.
The PR looks great and works great. We should indeed replace all panics caused by the
c.check()
.ErrClosing
can work, however, I think to avoid further confusion we had better use a new error and keep the original message. For example:ErrDedicatedClientRecycled = errors.New("dedicated client should not be used after recycled")
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.
Yep, will update PR - that was my first thought too but then I found ErrClosing and decided to re-use existing error. BTW, how about changing
should
->must
in error message?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.
Sounds good to me too. Just curious why you think a
must
is better.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 was thinking in terms of https://www.ietf.org/rfc/rfc2119.txt. But thinking more, given my personal use case, it seems
should
can fit here too. Let's go withshould
.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.
@rueian , so I started implementing an error as you suggested, and realized that I don't clearly see a semantic difference between ErrClosing and ErrDedicatedClientRecycled. Why do you think a separate error is better in this case to avoid the confusion and how it differs from ErrClosing?
From library user's perspective I think
ErrClosing
clearly states that the client was used after closing, whileErrDedicatedClientRecycled
exposes implementation details to the user, and eventually it may be more confusing to read. WDYT?Probably
ErrClosed
instead ofErrDedicatedClientRecycled
could be much more clear here ifErrClosing
does not semantically fit.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.
The message of
ErrClosing
isrueidis client is closing or unable to connect redis
. I think it conveys too much misleading information in this case.For example, when a user hits the
c.check()
and sees the message, he/she may wonder:Close()
on my client. Who closed my client? But it was actually he/she called thecancel()
.unable to connect redis
? Was there a networking issue? But it was actually he/she called thecancel()
.I think this is how
ErrDedicatedClientRecycled
differs fromErrClosing
. It serves thec.check()
only.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.
Thx for the answer. It's more clear to me now – so it's an error specific to the state of dedicated clients only. I just pushed the updated version, please check it out.