DEV Community

Nahum Litvin
Nahum Litvin

Posted on Originally published at catchkill9.dev on

A zero timeout in Go is not no timeout

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)