Skip to content

Commit 11f45bb

Browse files
suofacebook-github-bot
authored andcommitted
Fix TLS behavior for async endpoints too (#268)
Summary: Pull Request resolved: #268 I noted in D76603819/#267 that the approach I took did not fix TLS across sync and async endpoints, because the python code for those handlers ran in separate threads. This diff fixes that by consolidating all of our execution onto a dedicated thread running a Python event loop. We are careful to not run any Python code (except the initial instantiation of the `_Actor` object, which doesn't run any user code) inside this thread, thus preserving thread locality. As a related change, I moved the code for waiting the async endpoints as background tasks from Python to Rust. This has a number of advantages: - The control flow is simpler to understand—`handle` and `handle_def` are regular async functions, not sync functions that return coroutines. Responsibilities for scheduling/awaiting background tasks is no longer split between Python and Rust, it's pure Rust. - The error behavior is more correct. Previously, an uncaught error in a background task would *be silently dropped*, since we never directly awaited the `_complete()` task to get exceptions out. Now these tasks are modeled as hyperactor actors, and any uncaught failure will get propagated as a supervision event. I added some tests to this effect. ghstack-source-id: 290891150 exported-using-ghexport Reviewed By: mariusae Differential Revision: D76661196 fbshipit-source-id: 22ca47d61e8542014eefb37d7e250e88934cf6fd
1 parent 5e089f2 commit 11f45bb

File tree

5 files changed

+347
-281
lines changed

5 files changed

+347
-281
lines changed

0 commit comments

Comments
 (0)