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

Report context cancel cause in DoBatchWithOptions instead of ctx.Err(). #577

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

dastrobu
Copy link
Contributor

@dastrobu dastrobu commented Aug 26, 2024

What this PR does:

Report context cancel cause in DoBatchWithOptions instead of ctx.Err().

Which issue(s) this PR fixes:

Closes #576

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order ox entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@joe-elliott
Copy link
Member

I'm good on this change. It seems straightforward and propagates more info (if available) back to the caller. The ring is very specialized and highly critical code. Let me try to summon an expert to confirm this won't do anything unexpected.

joe-elliott
joe-elliott previously approved these changes Aug 29, 2024
@dastrobu dastrobu force-pushed the feature/cancel-cause branch from a6583a1 to a665d52 Compare August 30, 2024 07:49
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Cannot this introduce a subtle bugs in code that already uses cancelation with cause, but calls to DoBatchWithOptions do expect standard context errors to be returned?

WDYT about adding an option to DoBatchOptions struct to enable return of context.Cause(ctx) errors instead?

CHANGELOG.md Outdated Show resolved Hide resolved
Closes grafana#576

Signed-off-by: Daniel Strobusch <1847260+dastrobu@users.noreply.github.com>
@dastrobu dastrobu force-pushed the feature/cancel-cause branch from a665d52 to 878e835 Compare August 30, 2024 13:43
@dastrobu
Copy link
Contributor Author

Cannot this introduce a subtle bugs in code that already uses cancelation with cause, but calls to DoBatchWithOptions do expect standard context errors to be returned?

I think it is very unlikely, but definitely possible. I don't have a good idea right now why one would do that.

WDYT about adding an option to DoBatchOptions struct to enable return of context.Cause(ctx) errors instead?

It is a viable option. It adds some complexity and makes it less likely that callers of DoBatchOptions will adopt the new (preferred) error policy, as adding an extra flag is required.

If you prefer the safer but more complex option, I can adapt the PR accordingly.

@pstibrany
Copy link
Member

Cannot this introduce a subtle bugs in code that already uses cancelation with cause, but calls to DoBatchWithOptions do expect standard context errors to be returned?

I think it is very unlikely, but definitely possible. I don't have a good idea right now why one would do that.

I can imagine this scenario very easily, with different layers having different expectations. I don't see a good way to find this in practice, other than just making the change and testing it.

WDYT about adding an option to DoBatchOptions struct to enable return of context.Cause(ctx) errors instead?

It is a viable option. It adds some complexity and makes it less likely that callers of DoBatchOptions will adopt the new (preferred) error policy, as adding an extra flag is required.

We could also make the flag to be opt-out -- enable the new behaviour by default, but provide way to disable it in case it proves troublesome. (It is a possibly breaking change after all).

I would ask @colega for his opinion too, since he introduced context checks into this code.

@joe-elliott joe-elliott dismissed their stale review August 30, 2024 16:21

Dismissing my review b/c there are some obvious concerns here and I don't want this accidentally merged.

@dastrobu
Copy link
Contributor Author

dastrobu commented Sep 2, 2024

We could also make the flag to be opt-out -- enable the new behaviour by default, but provide way to disable it in case it proves troublesome.

I like the idea. It would be a good compromise between moving forward and reducing risk.
If this is consensus, I could add something like ReportContextErrInsteadOfCause to the DoBatchOptions.

@colega
Copy link
Contributor

colega commented Sep 2, 2024

As far as I understand context cancellations with cause, this LGTM.

I think adding the option would only make it harder to reason about in the future (as we all know nobody would remove that option).

@charleskorn
Copy link
Contributor

The cancellation.NewError / cancellation.NewErrorf functions might be helpful here: they're intended to be used as the cancellation cause and satisfy errors.Is(cause, context.Canceled).

Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you!

@pstibrany pstibrany merged commit 82cb21a into grafana:main Sep 3, 2024
5 checks passed
@dastrobu dastrobu deleted the feature/cancel-cause branch September 3, 2024 08:52
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.

Report context cancel cause in DoBatchWithOptions instead of ctx.Err().
5 participants