upfluence/{context,timeout}: propagate request deadlines outside of thrift contexts#39
Open
AlexisMontagne wants to merge 1 commit into
Open
upfluence/{context,timeout}: propagate request deadlines outside of thrift contexts#39AlexisMontagne wants to merge 1 commit into
AlexisMontagne wants to merge 1 commit into
Conversation
…and build timeout on top of it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 acrossUpfluence::Threadboundaries.Upfluence::Timeoutis 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_timeoutscoping (both restore on ensure),override: falsedefault always picks the tighter of two deadlines, thread wrapper propagates the parent deadline into childUpfluence::ThreadinstancesUpfluence.context: lazily initialised thread-local accessorUpfluence::Timeout.timeout: matches::Timeout.timeoutsignature, intersectssecwith the context deadline, raises immediately if effective timeout is already<= 0, wraps the call inwith_timeoutso downstream code sees the deadline throughoutRequestStapler: fix broken yield-in-lambda bug, wirerequest_timeoutintoUpfluence.context.with_timeoutso the context deadline is visible for the full request lifecyclePool#pop: intersect wait timeout with context deadlineThrift::Middleware::Timeout: swap::Timeout.timeoutforUpfluence::Timeout.timeout