-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 & context.WithCancelCause instead of context.WithTimeout & context.WithCancel #11280
Comments
This issue is currently awaiting triage. If CAPI contributors determine this is a relevant issue, they will accept it by applying the The 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. |
@fabriziopandini @chrischdi @vincepri @enxebre Opinions? |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale /help |
@sbueringer: GuidelinesPlease ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met. If this request no longer meets these requirements, the label can be removed In response to this:
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. |
Hi @sbueringer, I'm interested and would like to work on this issue if this is still relevant. Can you please confirm? |
It's still relevant. Feel free to go ahead |
/assign |
Hi @sbueringer, I looked around the repo and as you mentioned there are around 40 instances of Is this what you've been looking for or is there anything else that specific that needs to be done? For example diff --git a/controllers/clustercache/cluster_accessor_client.go b/controllers/clustercache/cluster_accessor_client.go
index 55fe61ca6..908800133 100644
--- a/controllers/clustercache/cluster_accessor_client.go
+++ b/controllers/clustercache/cluster_accessor_client.go
@@ -261,7 +261,7 @@ func createCachedClient(ctx context.Context, clusterAccessorConfig *clusterAcces
go cache.Start(cacheCtx) //nolint:errcheck
// Wait until the cache is initially synced.
- cacheSyncCtx, cacheSyncCtxCancel := context.WithTimeout(ctx, clusterAccessorConfig.Cache.InitialSyncTimeout)
+ cacheSyncCtx, cacheSyncCtxCancel := context.WithTimeoutCause(ctx, clusterAccessorConfig.Cache.InitialSyncTimeout, errors.New("timed out while waiting for caches to sync"))
defer cacheSyncCtxCancel()
if !cache.WaitForCacheSync(cacheSyncCtx) {
cache.Stop()
@@ -297,13 +297,13 @@ type clientWithTimeout struct {
var _ client.Client = &clientWithTimeout{}
func (c clientWithTimeout) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
- ctx, cancel := context.WithTimeout(ctx, c.timeout)
+ ctx, cancel := context.WithTimeoutCause(ctx, c.timeout, errors.New("timed out while retrieving object in cluster"))
defer cancel()
return c.Client.Get(ctx, key, obj, opts...)
} |
I think we should start using the With*Cause variants of these functions as they allow adding additional context. This should lead to better messages than the standard "context canceled" when a context is canceled.
I took a look at our code base and we have roughly 20 context.WithCancel & 20 context.WithTimeout so it shouldn't be a lot of work to audit all of them and see if we want to use the With*Cause funcs instead
The text was updated successfully, but these errors were encountered: