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

🌱Use context.WithTimeoutCause and context.WithCancelCause for better readability #11705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Amulyam24
Copy link
Contributor

@Amulyam24 Amulyam24 commented Jan 20, 2025

What this PR does / why we need it:
This PR replaces context.WithTimeoutCause and context.WithCancelCause instead of context.Timeout and context.WithCancel for better readability of issues when the standard context deadline exceeded error is emitted.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #11280

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label labels Jan 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign enxebre for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 20, 2025
@Amulyam24 Amulyam24 changed the title Use context.WithTimeoutCause instead of context.Timeout for better readability 🌱Use context.WithTimeoutCause instead of context.Timeout for better readability Jan 20, 2025
@Amulyam24
Copy link
Contributor Author

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

@Amulyam24
Copy link
Contributor Author

/cc @sbueringer

@sbueringer
Copy link
Member

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

Definitely fine to not change anything in test files

@sbueringer sbueringer added the area/misc Issues or PRs not related to any other area label Jan 21, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-area PR is missing an area label label Jan 21, 2025
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Thx for opening this PR. I think it's better to express "why the timeout/context expired" vs expressiong what we were doing when it expired. The latter is usually handled when we wrap the error

controllers/clustercache/cluster_accessor_client.go Outdated Show resolved Hide resolved
controllers/clustercache/cluster_accessor_client.go Outdated Show resolved Hide resolved
controllers/remote/cluster_cache_tracker.go Outdated Show resolved Hide resolved
controlplane/kubeadm/internal/etcd/etcd.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

On looking into the occurrences of context.WithCancel, there were mostly in testing files. I have added the changes to non testing files as of now. Please let me know if that has to be handled as well.

Not sure if you pushed your latest commit :) I didn't see any changes to context.Cancel in non-test files. (there are also a few more cases of context.WithTimeout in non-test files, but you might have been looking for initial feedback before addressing these :))

@Amulyam24
Copy link
Contributor Author

but you might have been looking for initial feedback before addressing these :))

That's right, I will address the review the comments and cover the remaining occurrences in non test files as well.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 22, 2025
@Amulyam24 Amulyam24 changed the title 🌱Use context.WithTimeoutCause instead of context.Timeout for better readability 🌱Use context.WithTimeoutCause and context.WithCancelCause for better readability Jan 22, 2025
@Amulyam24 Amulyam24 requested a review from sbueringer January 22, 2025 09:43
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 28, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/misc Issues or PRs not related to any other area cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use context.WithTimeoutCause & context.WithCancelCause instead of context.WithTimeout & context.WithCancel
3 participants