Skip to content

upfluence/{context,timeout}: propagate request deadlines outside of thrift contexts#39

Open
AlexisMontagne wants to merge 1 commit into
am/admin-serverfrom
am/context-timeout
Open

upfluence/{context,timeout}: propagate request deadlines outside of thrift contexts#39
AlexisMontagne wants to merge 1 commit into
am/admin-serverfrom
am/context-timeout

Conversation

@AlexisMontagne

Copy link
Copy Markdown
Member

Currently, deadline information only exists inside a Thrift context. Outside of that — in HTTP handlers, background jobs, pool waits — we have no way to know whether the caller's deadline has already passed or how much time remains. This makes it easy to do expensive work for requests that have already timed out on the client side.

This PR introduces Upfluence::Context, a lightweight per-thread construct that tracks a deadline and propagates it across Upfluence::Thread boundaries. Upfluence::Timeout is built on top of it as a drop-in for ::Timeout.timeout, ensuring that any timeout call is automatically capped by the current context deadline.

  • Upfluence::Context: with_deadline/with_timeout scoping (both restore on ensure), override: false default always picks the tighter of two deadlines, thread wrapper propagates the parent deadline into child Upfluence::Thread instances
  • Upfluence.context: lazily initialised thread-local accessor
  • Upfluence::Timeout.timeout: matches ::Timeout.timeout signature, intersects sec with the context deadline, raises immediately if effective timeout is already <= 0, wraps the call in with_timeout so downstream code sees the deadline throughout
  • RequestStapler: fix broken yield-in-lambda bug, wire request_timeout into Upfluence.context.with_timeout so the context deadline is visible for the full request lifecycle
  • Pool#pop: intersect wait timeout with context deadline
  • Thrift::Middleware::Timeout: swap ::Timeout.timeout for Upfluence::Timeout.timeout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants