Repository navigation
Fix short-read handling in task-sdk IPC framing - #69253
Conversation
Stream sockets are not required to return the full requested count from recv(), but the 4-byte length prefix on the supervisor↔subprocess socket was read with a single sock.recv(4). On a short read, the parsed length is garbage, which either raises msgspec.DecodeError in the subprocess or silently deadlocks the supervisor's selector reader (length_needed=0 makes the falsy payload check skip forever, so no frame is ever dispatched to handle_requests). Accumulate the header bytes on both sides, mirroring the payload accumulation that was already correct. Add regression tests using a socket that returns 2 bytes at a time to reliably reproduce the short read.
9c4841a to
ffe148c
Compare
|
Hi @ashb, could you take a look at the framing approach here when you have a chance? I’d appreciate your feedback on whether this is the right approach. Thanks! |
ashb
left a comment
There was a problem hiding this comment.
I think this is technically correct (the best kind of correct, clearly) -- were you actually able to hit this edge case?
|
Actually I haven’t hit it in practice, only reproduced it with the test. (I noticed this Big thanks for taking a look! |
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…9253) Stream sockets are not required to return the full requested count from recv(), but the 4-byte length prefix on the supervisor↔subprocess socket was read with a single sock.recv(4). On a short read, the parsed length is garbage, which either raises msgspec.DecodeError in the subprocess or silently deadlocks the supervisor's selector reader (length_needed=0 makes the falsy payload check skip forever, so no frame is ever dispatched to handle_requests). Accumulate the header bytes on both sides, mirroring the payload accumulation that was already correct. Add regression tests using a socket that returns 2 bytes at a time to reliably reproduce the short read. (cherry picked from commit f72e6c9) Co-authored-by: Andrew Chang <[email protected]>
Stream sockets are not required to return the full requested count from recv(), but the 4-byte length prefix on the supervisor↔subprocess socket was read with a single sock.recv(4). On a short read, the parsed length is garbage, which either raises msgspec.DecodeError in the subprocess or silently deadlocks the supervisor's selector reader (length_needed=0 makes the falsy payload check skip forever, so no frame is ever dispatched to handle_requests). Accumulate the header bytes on both sides, mirroring the payload accumulation that was already correct. Add regression tests using a socket that returns 2 bytes at a time to reliably reproduce the short read. (cherry picked from commit f72e6c9) Co-authored-by: Andrew Chang <[email protected]>
…71609) Stream sockets are not required to return the full requested count from recv(), but the 4-byte length prefix on the supervisor↔subprocess socket was read with a single sock.recv(4). On a short read, the parsed length is garbage, which either raises msgspec.DecodeError in the subprocess or silently deadlocks the supervisor's selector reader (length_needed=0 makes the falsy payload check skip forever, so no frame is ever dispatched to handle_requests). Accumulate the header bytes on both sides, mirroring the payload accumulation that was already correct. Add regression tests using a socket that returns 2 bytes at a time to reliably reproduce the short read. (cherry picked from commit f72e6c9) Co-authored-by: Andrew Chang <[email protected]>
…71609) Stream sockets are not required to return the full requested count from recv(), but the 4-byte length prefix on the supervisor↔subprocess socket was read with a single sock.recv(4). On a short read, the parsed length is garbage, which either raises msgspec.DecodeError in the subprocess or silently deadlocks the supervisor's selector reader (length_needed=0 makes the falsy payload check skip forever, so no frame is ever dispatched to handle_requests). Accumulate the header bytes on both sides, mirroring the payload accumulation that was already correct. Add regression tests using a socket that returns 2 bytes at a time to reliably reproduce the short read. (cherry picked from commit f72e6c9) Co-authored-by: Andrew Chang <[email protected]>
Fix short-read handling in task-sdk IPC framing
related: #64212
Why
The 4-byte length prefix on the supervisor ↔ subprocess socket is read with a single
sock.recv(4)on both ends. Stream sockets don't guaranteerecvreturns the full requested count — on a short read the parsed length is garbage.Two symmetric sites hit it:
comms.py._read_frame(subprocess reading a response from the supervisor): raisesmsgspec.DecodeError: Input data was truncated.supervisor.py.length_prefixed_frame_reader(supervisor reading a request via selector callback): silently deadlocks.int.from_bytes(b"\x00\x00", ...) = 0→ the payload branch's
if length_needed and buffer:skips on falsy 0→ no frame is ever dispatched to
handle_requests. Reader stuck, no exception, no log.It may affects every
SUPERVISOR_COMMS.send(), including XCom, Variable, Connection, HITL, secrets backend, etc. (the IPC critical path for every task) Rare on loopback (small writes usually deliver atomically) but not guaranteed by POSIX; reproducible with a socket that returns 2 bytes at a time.What
Accumulate the header bytes on both sides, mirroring the existing payload accumulation:
comms.py: blockingwhile len(len_buf) < 4: recv(4 - len(len_buf))in the same call.supervisor.py: nonlocalheader_bufferthat persists across selector callbacks; the header branch returnsTrue(wait for more) until 4 bytes are collected.Regression tests use a
ChunkedSocketthat returns 2 bytes at a time; both fail on current main and pass with the fix.The traceback in #64212 passes through the same
recv(4)call site, but I have not verified if this fix could solve that issue yet.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code Opus 4.7 following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.