Skip to main content

Deadlines and backpressure

What this concept is​

A fixed frame deadline limits elapsed time from the first header byte, while an idle timeout limits time since recent activity. They are different policies. Backpressure bounds admitted work when the consumer is slower than the incoming stream.

Why it matters here​

Resetting a frame deadline on every new byte lets a peer keep incomplete state alive indefinitely. A parser with small retained buffers can still exhaust a server through many connections or an unbounded queue of completed messages.

Concrete example​

With a ten-tick frame budget, receive the first header byte at 0 and another at 9. The frame still expires at 10. A final completing chunk at exactly 10 is rejected because expiry is checked first. If completion occurs at 9, the next frame receives its own start time.

Common confusion / misconception​

The decoder cannot notice time passing without a call. The event loop must arrange poll at the deadline even when no bytes arrive. Simulated ticks are not a real network measurement. Also, a request timeout does not establish that the remote side effect was rolled back.

How to use it​

Use a monotonic clock and consistent units. Schedule deadline checks independently of reads, bound recv chunks, cap queued messages and active connections, and stop admitting work when capacity is exhausted. Connect to the bounded queue’s shutdown contract rather than spawning an unlimited worker per message.

Check yourself​

Does this decoder time out an entirely idle new connection? No; there is no frame yet. An adapter may need a separate idle deadline. Does TCP flow control alone enforce your application queue limit? No; admission and buffering policy still matter.

Mini drill or application​

Trace progress at ticks 0,9,10 under a fixed deadline and under a reset-on-progress bug. Then draw the adapter’s EOF, cancellation, protocol-error and queue-full paths. Explain which resources each path releases.

Read this only if stuck​

Review layering in Computer Networking chapter 1 and Module 3’s queue contract; assign each deadline and bound to one component.