Skip to content

Fix short-read handling in task-sdk IPC framing - #69253

Merged
ashb merged 1 commit into
apache:mainfrom
Andrushika:fix-task-sdk-framing-short-read
Aug 14, 2026
Merged

ashb merged 1 commit into
apache:mainfrom
Andrushika:fix-task-sdk-framing-short-read

Conversation

@Andrushika

@Andrushika Andrushika commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

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 guarantee recv returns 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): raises msgspec.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: blocking while len(len_buf) < 4: recv(4 - len(len_buf)) in the same call.
  • supervisor.py: nonlocal header_buffer that persists across selector callbacks; the header branch returns True (wait for more) until 4 bytes are collected.

Regression tests use a ChunkedSocket that 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?
  • Yes (please specify the tool below)

Generated-by: Claude Code Opus 4.7 following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jul 2, 2026
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.
@Andrushika
Andrushika force-pushed the fix-task-sdk-framing-short-read branch from 9c4841a to ffe148c Compare July 4, 2026 19:49
@Andrushika

Copy link
Copy Markdown
Contributor Author

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 ashb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is technically correct (the best kind of correct, clearly) -- were you actually able to hit this edge case?

@ashb ashb added this to the Airflow 3.3.2 milestone Aug 13, 2026
@Andrushika

Andrushika commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Actually I haven’t hit it in practice, only reproduced it with the test. (I noticed this
while reading through the code)
It should be extremely rare on the local socketpair, but I thought it still be worth fixing since it could leave the task stuck.

Big thanks for taking a look!

@ashb
ashb merged commit f72e6c9 into apache:main Aug 14, 2026
103 checks passed
@Andrushika
Andrushika deleted the fix-task-sdk-framing-short-read branch August 14, 2026 09:07
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 14, 2026
…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]>
potiuk pushed a commit that referenced this pull request Aug 17, 2026
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]>
potiuk pushed a commit that referenced this pull request Aug 17, 2026
…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]>
vatsrahul1001 pushed a commit that referenced this pull request Sep 7, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants