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

Update eval_cancel_error logic to separate context canceled, timeout errors #7202

Merged

Conversation

mchitten
Copy link
Contributor

@mchitten mchitten commented Dec 2, 2024

Why the changes in this PR are needed?

While the eval_cancel_error: caller cancelled query execution error is useful in identifying requests that stopped, I propose that it's a little too vague because it absorbs both context.Canceled and context.DeadlineExceeded errors. It's useful to differentiate these errors as it gives a clue to whether the user intentionally stopped the request, or the request exeeded some deadline from the caller. Without a change similar to this, it's much more difficult to tell why a call to Eval failed.

What are the changes in this PR?

This adds logic to topdown/eval.go to differentiate context errors. It has the same eval_cancel_error prefix as before, but can now return an error that gives more clues:

eval_cancel_error: context deadline exceeded
eval_cancel_error: context canceled

Notes to assist PR review:

Further comments:

An alternative here could be just to return the e.ctx.Err() in the existing logic, but that does retain the more vague error message.

@mchitten mchitten force-pushed the context-error-handling branch from b162ab4 to 2f52bb2 Compare December 2, 2024 17:35
This changes the `eval_cancel_error` logic to differentiate between
context.Canceled and context.DeadlineExceeded errors, because they are
distinct errors. By differentiating here, callers will be able to
determine if a call was stopped because a caller stopped the request, or
because the request went over some imposed deadline.

Signed-off-by: Mike Chittenden <[email protected]>
@mchitten mchitten force-pushed the context-error-handling branch from 2f52bb2 to 5bc8776 Compare December 2, 2024 17:42
@mchitten
Copy link
Contributor Author

mchitten commented Dec 2, 2024

Looking at the test failures, seems like they might be flakes fixed by #7188

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks!

@anderseknert anderseknert merged commit a241c87 into open-policy-agent:main Dec 3, 2024
28 checks passed
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.

4 participants