A job has a three-second user-visible budget. It spends 2.2 seconds in the queue. Giving the provider a fresh three-second timeout when the worker starts allows that single hop to outlive the caller's entire budget. The worker needs the remaining budget after queueing, including time reserved for its own cleanup.
Derive a usable timeout
At the edge, establish an end-to-end deadline. Within one process, measure elapsed durations with a monotonic clock. Monotonic clock readings from different hosts are not generally comparable. Use the RPC framework's deadline propagation where available. For durable queues, record an absolute expiry using a documented time basis, allow for clock error and check it when the job is dequeued. Forwarding an unchanged relative timeout through a long queue would reset the budget.
Suppose the remaining budget is 800 ms, cleanup needs 150 ms, the hop cap is 500 ms and a useful attempt requires at least 200 ms. The usable timeout is the smaller of 500 and 650 ms, so the hop receives 500 ms. With only 280 ms left, 130 ms would remain after cleanup. Decline to start this attempt. Compute that limit again after any backoff or queue delay.
Test from the caller's clock
Use a fake clock, a queue with controllable delay and an upstream stub that can return late. Record every start time, granted timeout and disposition. Assert no new hop starts after its usable deadline. A caller timing out does not automatically stop arbitrary work already running on another host: the worker or downstream service must cooperate with cancellation. A side effect completed after the caller stopped waiting still needs its receipt reconciled.
Watch both queue wait and service time. A high timeout count with most of the budget spent before dispatch points to scheduling or capacity, not automatically to a slow provider.
gRPC deadline propagation · HTTP semantics, §9.2.2
This article was created with AI assistance.
Top comments (0)