A zero timeout in Go is not no timeout
context.WithTimeout(ctx, 0) hands you a context that is already dead.
While working on snapshotter timeouts in containerd, I assumed a timeout of 0 meant "no limit". It doesn't.
ctx, cancel := context.WithTimeout(context.Background(), 0)
defer cancel()
fmt.Println(ctx.Err()) // context deadline exceeded
The deadline is now, so the context is expired before the first call. containerd's timeout.WithContext passes the configured value straight to context.WithTimeout, so a key set to 0 fails every call on the spot.
That's why the new default_timeout for proxy snapshotters is off when empty, and only wraps calls whose context has no deadline yet: https://github.com/containerd/containerd/pull/14187
A 12 second go run settled it. Cheaper than arguing about it.
References
- PR · merged containerd/containerd#14187: snapshots/proxy: add optional default_timeout for proxy snapshotter calls
Comments