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

proposal: x/time/rate: make Wait return an error that Is(DeadlineExceeded) for deadline miss #54541

Closed
BoyceHan opened this issue Aug 19, 2022 · 9 comments
Assignees
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Proposal
Milestone

Comments

@BoyceHan
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.6 linux/amd6

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

Not relevant

What did you do?

err := limiter.Wait(ctxDeadlineExceed)
error.Is(err, context.DeadlineExceed) -> false

What did you expect to see?

error.Is(err, context.DeadlineExceed) -> true

What did you see instead?

error.Is(err, context.DeadlineExceed) -> false

Suggestion to Fix

at rate.go:260, REPEAL

return fmt.Errorf("rate: Wait(n=%d) would exceed context deadline", n)

SUBSTITUTE

return fmt.Errorf("rate: Wait(n=%d) would cause %w", n, context.DeadlineExceed)
@gopherbot gopherbot added this to the Unreleased milestone Aug 19, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 19, 2022
@seankhliao
Copy link
Member

cc @Sajmani

@Sajmani
Copy link
Contributor

Sajmani commented Aug 21, 2022

This seems reasonable, though I'd leave the error text unchanged to avoid breaking anything that tests for it. We can still arrange for the returned error to wrap context.DeadlineExceeded so that the errors.Is test works.

@Sajmani Sajmani changed the title x/time/rate: context deadline exceed error is not standardised x/time/rate: make lim.Wait(ctx) return an err that satisfies errors.Is(err, context.DeadlineExceeded) when ctx.Err() == context.DeadlineExceeded Aug 21, 2022
@Sajmani Sajmani self-assigned this Aug 21, 2022
@gopherbot
Copy link

Change https://go.dev/cl/433136 mentions this issue: rate: make errors.Is(err, context.DeadlineExceeded) work for lim.Wait errors

@rsc rsc changed the title x/time/rate: make lim.Wait(ctx) return an err that satisfies errors.Is(err, context.DeadlineExceeded) when ctx.Err() == context.DeadlineExceeded proposal: x/time/rate: make lim.Wait(ctx) return an err that satisfies errors.Is(err, context.DeadlineExceeded) when ctx.Err() == context.DeadlineExceeded Oct 26, 2022
@rsc rsc changed the title proposal: x/time/rate: make lim.Wait(ctx) return an err that satisfies errors.Is(err, context.DeadlineExceeded) when ctx.Err() == context.DeadlineExceeded proposal: x/time/rate: make Wait return an error that Is(DeadlineExceeded) for deadline miss Oct 26, 2022
@rsc
Copy link
Contributor

rsc commented Oct 26, 2022

Retitled, but one problem with this proposal (or at least the implementation) is that sometimes Wait returns an error because it knows that waiting would exceed the deadline, but the deadline has not been exceeded yet. So if we make the change in the CL, Wait(ctx) might return something that Is(DeadlineExceeded) even if ctx.Err() == nil (!= DeadlineExceeded). That might be confusing.

@rsc
Copy link
Contributor

rsc commented Oct 26, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Nov 9, 2022

@GODCALLMEGOD why do you want this error to change? What is the use case?

There is a subtle difference between the current "would exceed context deadline" and the suggested change to DeadlineExceeded, which means "did exceed context deadline". It's not clear to me that we should return the latter for the former case.

@rsc
Copy link
Contributor

rsc commented Nov 30, 2022

In the absence of a compelling reason for the change, this seems like a no. It seems like a mistake to say the deadline is exceeded when it has not yet been exceeded. It would be wrong for code to see DeadlineExceeded and then abort other parts of the work, for example.

@rsc
Copy link
Contributor

rsc commented Dec 7, 2022

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Dec 14, 2022

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc closed this as completed Dec 14, 2022
@golang golang locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Proposal
Projects
None yet
Development

No branches or pull requests

5 participants