Skip to content

fix(relay): harden large download streaming#1382

Closed
maybeknott wants to merge 3 commits into
therealaleph:mainfrom
maybeknott:fix/download-stream-resilience
Closed

fix(relay): harden large download streaming#1382
maybeknott wants to merge 3 commits into
therealaleph:mainfrom
maybeknott:fix/download-stream-resilience

Conversation

@maybeknott
Copy link
Copy Markdown

Builds on CaptainMirage's relay download-resilience work with a clean branch based on current main.

This PR preserves the two reliability commits from #1346 and adds the missing config-facing completion layer:

  • separates relay header/connect timeout from per-body-chunk stream idle timeout;
  • preserves stream_timeout_secs through desktop UI save round-trips;
  • documents request_timeout_secs and stream_timeout_secs in TOML examples;
  • updates English and Persian guides to reflect active range-aware download streaming and its remaining Apps Script quota cost;
  • adds focused regression coverage for timeout parsing/defaults, JSON migration preservation, resume Range parsing, and non-zero-offset probe validation.

The branch intentionally excludes #1346's unrelated compact logging/UI timestamp changes and release artifact churn so the relay behavior can be reviewed independently.

Verification:

  • git diff --check passes.
  • Focused Cargo tests are currently blocked locally by the uncached winnow v0.7.15 dependency when using --offline.

CaptainMirage and others added 3 commits May 24, 2026 13:52
Inside the MITM TLS session, detect Connection: Upgrade + Upgrade:
websocket before hitting the Apps Script relay. Establish a direct TLS
connection to the real server (via upstream_socks5 if configured),
relay the upgrade handshake, then splice both directions with
copy_bidirectional. Apps Script cannot hold persistent connections so
the bypass is the only viable path for wss://.

Split request_timeout_secs (header/connect, 30s) from a new
stream_timeout_secs (per-chunk body idle, default 300s) so large range
downloads through Apps Script are not killed mid-transfer by the
batch_timeout firing during the body drain phase.
Handle idempotent exit-node timeouts by falling back to direct Apps Script, route Range: bytes=N- requests through parallel resume streaming, and send TLS close_notify on shutdown so wget/curl can resume from the correct offset.
Preserve the new body-stream idle timeout across every config-facing path that can rewrite configuration. Desktop Save now round-trips stream_timeout_secs alongside request_timeout_secs, preventing hand-edited large-download timeout settings from being silently dropped.

Document the split timeout model in the TOML examples and user guides: request_timeout_secs bounds relay connection and response-header arrival, while stream_timeout_secs bounds idle time between body chunks after headers have arrived. This keeps dead destinations bounded without aborting slow range downloads mid-stream.

Update the guide's implementation matrix to reflect the active range-aware download path and its remaining quota cost. Large range-capable responses can stream in chunks and resume cleanly with Range: bytes=N-, but each chunk remains an Apps Script UrlFetchApp call.

Add regression coverage for TOML parsing and defaults, JSON migration round-trip preservation, Range header start parsing, and validation of non-zero-offset resume probes.
@github-actions github-actions Bot added the type: fix fix: PR — auto-applied by release-drafter label May 24, 2026
@CaptainMirage
Copy link
Copy Markdown
Contributor

CaptainMirage commented May 24, 2026

im sorry did you just basically pull my commits and added a config update when i already added an automatic system for the configs to update based on what values are being used in #1317 ? even worst case scenario if it cant update the config it just uses the default and there is no need to change that in 90% of cases.

there is no need to update the docs just to tell a normal user that the download now works normally, that shouldve been there in the first place and it was a bug not a feature to advertise, the docs are already packed with things that are not needed we dont need more clutter, we are not trying to confuse or scare away a new user its meant to be a guide not a world map

@CaptainMirage
Copy link
Copy Markdown
Contributor

just to add some context here: my concern isnt about blocking improvements, its about avoiding duplicate work. The behaviour this PR is touching is already handled automatically in my earlier PR (#1317), including sane defaults when config updates aren’t possible, so introducing a second, overlapping approach and extra docs for it could make things harder to maintain and more confusing for users in the long run. I’d prefer if we could either build on top of the existing implementation or consolidate the changes rather than having parallel solutions. and specifically in this case,the default stream_timeout_secs being 300 is fine and in most cases doesnt need to be changed since at that point if you are having problems with the stream it might not be the programs issue

and the UI update isnt needed, a lot of variables are missing from there, i am working on an overhauled version of the UI since it really needs one and a lot of things need to be changed around

@maybeknott
Copy link
Copy Markdown
Author

just to add some context here: my concern isnt about blocking improvements, its about avoiding duplicate work. The behaviour this PR is touching is already handled automatically in my earlier PR (#1317), including sane defaults when config updates aren’t possible, so introducing a second, overlapping approach and extra docs for it could make things harder to maintain and more confusing for users in the long run. I’d prefer if we could either build on top of the existing implementation or consolidate the changes rather than having parallel solutions. and specifically in this case,the default stream_timeout_secs being 300 is fine and in most cases doesnt need to be changed since at that point if you are having problems with the stream it might not be the programs issue

and the UI update isnt needed, a lot of variables are missing from there, i am working on an overhauled version of the UI since it really needs one and a lot of things need to be changed around

That's fair.

I’ll close this PR and stop treating it as a separate source of truth. The download-resilience behavior should continue through #1346/#1317, and any useful pieces from my branch can be proposed later only as narrow follow-ups that do not overlap with your config migration or UI work.

I also agree on the UI/docs point. I’ll avoid adding user-guide text for this bug fix and won’t touch the desktop UI for stream_timeout_secs, since you already have broader UI work in progress and the default is sane for normal users.

Thanks for clarifying the #1317 behavior. I should have checked that path more carefully before opening this. Sorry for the frustration.

@maybeknott maybeknott closed this May 24, 2026
@CaptainMirage
Copy link
Copy Markdown
Contributor

just to add some context here: my concern isnt about blocking improvements, its about avoiding duplicate work. The behaviour this PR is touching is already handled automatically in my earlier PR (#1317), including sane defaults when config updates aren’t possible, so introducing a second, overlapping approach and extra docs for it could make things harder to maintain and more confusing for users in the long run. I’d prefer if we could either build on top of the existing implementation or consolidate the changes rather than having parallel solutions. and specifically in this case,the default stream_timeout_secs being 300 is fine and in most cases doesnt need to be changed since at that point if you are having problems with the stream it might not be the programs issue
and the UI update isnt needed, a lot of variables are missing from there, i am working on an overhauled version of the UI since it really needs one and a lot of things need to be changed around

That's fair.

I’ll close this PR and stop treating it as a separate source of truth. The download-resilience behavior should continue through #1346/#1317, and any useful pieces from my branch can be proposed later only as narrow follow-ups that do not overlap with your config migration or UI work.

I also agree on the UI/docs point. I’ll avoid adding user-guide text for this bug fix and won’t touch the desktop UI for stream_timeout_secs, since you already have broader UI work in progress and the default is sane for normal users.

Thanks for clarifying the #1317 behavior. I should have checked that path more carefully before opening this. Sorry for the frustration.

no frustration here mate dont get me wrong, the TOML move was quite a big PR i didnt mention every single detail i changed and made in the body, just wanted to say it here just so you know it already exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix fix: PR — auto-applied by release-drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants