Skip to content

fix(http-proxy): drain large m3u rewrite bodies#488

Merged
stackia merged 3 commits into
mainfrom
codex/http-proxy-m3u-drain
May 18, 2026
Merged

fix(http-proxy): drain large m3u rewrite bodies#488
stackia merged 3 commits into
mainfrom
codex/http-proxy-m3u-drain

Conversation

@stackia
Copy link
Copy Markdown
Owner

@stackia stackia commented May 18, 2026

Summary

Fix HTTP proxy M3U rewrite buffering so large playlists keep draining upstream reads under edge-triggered polling.

Related: #486

Root Cause

The M3U rewrite path buffered upstream body bytes but returned 0 before the body was complete. The outer read loop treats 0 as no progress, so it could stop before reaching EAGAIN and miss remaining buffered bytes.

Validation

  • cmake --build build -j$(getconf _NPROCESSORS_ONLN)
  • ./scripts/run-e2e.sh test_http_proxy_m3u_rewrite.py -k large_playlist_body_is_fully_buffered
  • uv run --group dev clang-format --dry-run --Werror src/http_proxy.c
  • uv run --group dev ruff check e2e/test_http_proxy_m3u_rewrite.py
  • uv run --group dev ruff format --check e2e/test_http_proxy_m3u_rewrite.py

@stackia stackia marked this pull request as ready for review May 18, 2026 10:37
Copilot AI review requested due to automatic review settings May 18, 2026 10:37
@github-actions
Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-488.eastasia.1.azurestaticapps.net

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to fix HTTP proxy M3U rewrite buffering so large playlists continue draining upstream reads under edge-triggered polling.

Changes:

  • Reports buffered M3U body reads as progress during rewrite mode.
  • Reports initial body bytes received with headers as progress.
  • Adds an E2E regression test for large playlist rewrite buffering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/http_proxy.c Adjusts M3U rewrite receive progress signaling.
e2e/test_http_proxy_m3u_rewrite.py Adds a large playlist rewrite regression test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http_proxy.c
return http_proxy_finalize_rewrite(session);
}

bytes_forwarded = (int)initial_size;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed by the second commit (f5b918d) which added socket_progress fallback — the header-only case now returns socket_progress (the full recv byte count) instead of 0, so the drain loop stays alive. Additionally updated the doc comment and renamed the accumulator to progress in 5a1a0d9 to reflect the actual semantics.

@github-actions
Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-488.eastasia.1.azurestaticapps.net

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/http_proxy.c
}

return bytes_forwarded;
return bytes_forwarded > 0 ? bytes_forwarded : socket_progress;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Went with updating the contract — renamed the accumulator to progress and updated the doc to say "positive value if progress was made (data received/forwarded)". No caller uses the positive value semantically, so separating the signals would be unnecessary complexity.

Comment thread src/http_proxy.c
}

return 0; /* Keep buffering */
return (int)received; /* Progress: keep draining edge-triggered sockets */
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Updated the doc comment to say "positive value if progress was made" instead of "bytes forwarded", and renamed the accumulator in http_proxy_handle_socket_event from bytes_forwarded to progress. The only caller (stream.c) only checks < 0, so no functional change.

…andler

The M3U rewrite drain fix changed the return semantics from "bytes
forwarded to client" to "progress made" (including buffered-but-not-yet-
forwarded bytes). Update the doc comment and rename the accumulator
variable to reflect this.
@stackia stackia enabled auto-merge (squash) May 18, 2026 11:10
@github-actions
Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-488.eastasia.1.azurestaticapps.net

@stackia stackia merged commit 205db18 into main May 18, 2026
10 checks passed
@stackia stackia deleted the codex/http-proxy-m3u-drain branch May 18, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants