gRPC deadlines and errors
Prerequisite: node-rpc-and-protobuf-contracts. Objective: Trace deadline propagation. Each example is independent. Tested with Node.js 22.16.0 on Linux. Save as main.mjs in a fresh disposable directory and run node main.mjs. These are static code blocks; external system behavior is not established by a local model.
How it works
Budget time across downstream calls rather than granting each dependency a fresh full timeout. In gRPC, DEADLINE_EXCEEDED indicates that the call exceeded its time budget; CANCELLED, INVALID_ARGUMENT, NOT_FOUND and UNAVAILABLE have distinct meanings. Retry only when the operation is safe to repeat and the remaining budget permits it. Cancellation is cooperative; a server must stop work and release resources where possible. A mutation may require an idempotency key and reconciliation.
Propagate a shrinking deadline
import assert from 'node:assert/strict';function budget(deadline,now,reserve){return Math.max(0,deadline-now-reserve);}assert.equal(budget(100,105,5),0);console.log(budget(100,35,10),budget(100,90,10));Expected output:
55 0The downstream budget excludes time reserved for the caller.
Observe cooperative cancellation
import assert from 'node:assert/strict';import {setTimeout as delay} from 'node:timers/promises';const controller=new AbortController();const pending=delay(100, 'done',{signal:controller.signal});controller.abort();await assert.rejects(pending,{name:'AbortError'});console.log('cancelled');Expected output:
cancelledA real Node timer rejects on abort; this is not a gRPC transport test.
Common mistake
Do not blindly retry every failure or treat UNAVAILABLE as evidence that no mutation took place.
Practice
Calculate the remaining budget after 35 ms of a 100 ms request, reserving 10 ms for the response.
Reference candidate: node-grpc-deadlines-and-errors-lookup (route unverified). Documentation anchors: https://grpc.io/docs/guides/deadlines/, https://grpc.io/docs/guides/status-codes/. External versions and full integration are pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
gRPC deadlines and errors — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
What does a timed-out mutation prove?
What should a downstream deadline respect?
When is retry most appropriate?