Skip to content
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 3 commits into from
Jul 26, 2024

Conversation

FZambia
Copy link
Contributor

@FZambia FZambia commented Jul 25, 2024

Relates #586

This PR contains changes to avoid panicking with DedicatedClient should not be used after recycled, and return an error (specifically, ErrClosing) instead.

Please take a look. The thing I personally not sure whether it's semantically correct to use ErrClosing in these places. At first glance seems logical, but probably will require adjustments. Also, #586 mentions only panic for Do call, but I guess it should be extrapolated to all methods to fully eliminate panic.

@@ -392,4 +392,3 @@ func dial(dst string, opt *ClientOption) (conn net.Conn, err error) {
}

const redisErrMsgCommandNotAllow = "command is not allowed"
const dedicatedClientUsedAfterReleased = "DedicatedClient should not be used after recycled"
Copy link
Collaborator

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")

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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 with should.

Copy link
Contributor Author

@FZambia FZambia Jul 26, 2024

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, while ErrDedicatedClientRecycled exposes implementation details to the user, and eventually it may be more confusing to read. WDYT?

Probably ErrClosed instead of ErrDedicatedClientRecycled could be much more clear here if ErrClosing does not semantically fit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message of ErrClosing is rueidis 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:

  1. I didn't call Close() on my client. Who closed my client? But it was actually he/she called the cancel().
  2. unable to connect redis? Was there a networking issue? But it was actually he/she called the cancel().

I think this is how ErrDedicatedClientRecycled differs from ErrClosing. It serves the c.check() only.

Copy link
Contributor Author

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.

@FZambia FZambia changed the title Avoid panic on use after close, return error instead Avoid panic when using dedicated client after being recycled, return an error instead Jul 26, 2024
@rueian rueian merged commit 53f92e1 into redis:main Jul 26, 2024
19 checks passed
@FZambia FZambia deleted the error_instead_of_panic branch July 26, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants