Commit 9df8399
Match async client channel declaration to definition
Summary:
Every thrift-python async client crashes with a heap-use-after-free under libc++ on its first RPC. This is a latent bug for any service that does a Thrift RPC over ServiceRouter / get_client faults inside the native client dispatch.
Root cause: `thrift/lib/python/client/async_client.pxd` declared `cdef bind_client(self, cRequestChannel_ptr&& channel)`, but `async_client.pyx` defined it by value as `cdef bind_client(self, cRequestChannel_ptr channel)`. Cross-module callers such as `requestchannel_callback` in `async_client_factory.pyx` compile against the `.pxd`, so they emit the vtable slot as Ptr&& and pass a reference to the channel `unique_ptr`, which lives inside the resolved `folly::Future` Core. The by-value function body then reads that reference as if it were the `unique_ptr` object, so `OmniClient::channel_` ends up pointing at the Core storage instead of the channel. The real channel stays owned by the Core and is freed by `~Core`, so the first RPC reads freed memory.
Fix: drop the `&&` from the `.pxd` declaration so it matches the by-value `.pyx` definition, which is also consistent with the neighboring `bind_client_shared` signature style. The channel is still moved end-to-end: callers pass `cmove(channel._cpp_obj)`, `bind_client` receives the move-only `cRequestChannel_ptr` by value, and then moves it into `OmniClient`.
Also adds a named regression test exercising async `get_client` plus first RPC, which heap-use-after-frees under libc++ without this fix. The BUCK change is autodeps making the pre-existing `thrift.python.common` import explicit on the client test targets.
Reviewed By: iahs
Differential Revision: D109862203
fbshipit-source-id: 83ef740c3c41f8b9fd04e6376c265147b3d56d6f1 parent 517f1e2 commit 9df8399
2 files changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
0 commit comments