viewer: reset chunk download deadline while body bytes stream (VIEWER-CHUNK-IDLE-TIMEOUT) #651

Open
github-bot wants to merge 1 commit from github-bot/gh-651 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-24 10:59 UTC · original
kirigayakazima:fix/viewer-chunk-idle-timeout → main · +252 −7 · 2 files · 1 commits · open

Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (#14)

What and why

Follows up on @⁠slauko's finding in #14 (comment 7128949696), where valid multi-hundred-megabyte clay chunks (up to 773 MB) hit CHUNK_DOWNLOAD_TIMEOUT_MS (30 s) on a cold read because the timer bounded the entire download wall-clock duration rather than idle stalls.

  • viewer/index.html: add parseContentLength / readChunkBytes so loadChunk streams chunks via response.body.getReader() and resets the 30 s deadline whenever non-empty body bytes arrive:
    • Headers alone and zero-byte chunks do not reset the deadline.
    • Preallocates a single Uint8Array (capped at 1 GiB) when an uncompressed Content-Length is valid, spilling gracefully if more bytes arrive or slicing if the stream ends early; omits preallocation when Content-Encoding is set.
    • Cancels the stream reader on AbortSignal abort and releases the lock in finally.
    • Falls back to response.arrayBuffer() when response.body?.getReader is absent.
  • tests/test_viewer_streaming.cjs: extend the mock fetch/GLTFLoader fixture with streamHeaders and parses and add 5 unit test groups covering sliding idle timeouts (with and without Content-Length), headers-only stalls, empty-chunk stalls, Content-Length mismatches / Content-Encoding, and mid-transfer cancellation/drop cleanup.

Tested

On Windows 11 x64 (Node v24.19.0, Python 3.14.7) at $sha, synthetic fixtures only (no game data):

  • node --test tests/test_viewer_streaming.cjs — 67 passed, 0 failed (includes 5 new streamed-timeout / assembly tests)
  • node --test tests/test_viewer_studio.cjs — 11 passed, 0 failed
  • python -I tests/test_viewer_cdn_integrity.py — 10 ran, OK
  • python -I tests/test_viewer_serve.py — 39 ran, OK (1 skipped)
  • python -I tests/test_ci_registration.py — 15 ran, OK
  • python -I tests/test_text_write_line_endings.py — 3 ran, OK
  • python -I tests/test_check_no_game_data.py & python -I scripts/check_no_game_data.py — exit 0
  • python -m compileall -q make_game.py tools tests — exit 0

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main (21625bca) and merges cleanly (a conflicting pull request is labeled
    eeds rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — viewer streaming only)
**@⁠kirigayakazima** on GitHub · 2026-11-24 10:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/651) `kirigayakazima:fix/viewer-chunk-idle-timeout` → `main` · +252 −7 · 2 files · 1 commits · open Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Follows up on @⁠slauko's finding in [#14 (comment 7128949696)](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14), where valid multi-hundred-megabyte clay chunks (up to 773 MB) hit `CHUNK_DOWNLOAD_TIMEOUT_MS` (30 s) on a cold read because the timer bounded the entire download wall-clock duration rather than idle stalls. - `viewer/index.html`: add `parseContentLength` / `readChunkBytes` so `loadChunk` streams chunks via `response.body.getReader()` and resets the 30 s deadline whenever non-empty body bytes arrive: - Headers alone and zero-byte chunks do not reset the deadline. - Preallocates a single `Uint8Array` (capped at 1 GiB) when an uncompressed `Content-Length` is valid, spilling gracefully if more bytes arrive or slicing if the stream ends early; omits preallocation when `Content-Encoding` is set. - Cancels the stream reader on `AbortSignal` abort and releases the lock in `finally`. - Falls back to `response.arrayBuffer()` when `response.body?.getReader` is absent. - `tests/test_viewer_streaming.cjs`: extend the mock `fetch`/`GLTFLoader` fixture with `streamHeaders` and `parses` and add 5 unit test groups covering sliding idle timeouts (with and without `Content-Length`), headers-only stalls, empty-chunk stalls, `Content-Length` mismatches / `Content-Encoding`, and mid-transfer cancellation/drop cleanup. ### Tested On Windows 11 x64 (Node v24.19.0, Python 3.14.7) at $sha, synthetic fixtures only (no game data): - `node --test tests/test_viewer_streaming.cjs` — 67 passed, 0 failed (includes 5 new streamed-timeout / assembly tests) - `node --test tests/test_viewer_studio.cjs` — 11 passed, 0 failed - `python -I tests/test_viewer_cdn_integrity.py` — 10 ran, OK - `python -I tests/test_viewer_serve.py` — 39 ran, OK (1 skipped) - `python -I tests/test_ci_registration.py` — 15 ran, OK - `python -I tests/test_text_write_line_endings.py` — 3 ran, OK - `python -I tests/test_check_no_game_data.py` & `python -I scripts/check_no_game_data.py` — exit 0 - `python -m compileall -q make_game.py tools tests` — exit 0 GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current main (21625bca) and merges cleanly (a conflicting pull request is labeled eeds rebase). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — viewer streaming only)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:57 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-24 11:27 UTC · original · reviewed

Independent verification at 5e19f489: all 67 viewer streaming tests and 11 viewer studio tests passed. I also exercised the downloader over loopback HTTP with a shortened deadline and synthetic bytes. With nonempty body fragments arriving within each idle interval but taking longer than one interval in total, the base aborted and the PR returned the complete byte sequence. Both revisions still aborted a stalled response.

AI-assisted testing.

**@⁠lixonik** on GitHub · 2026-11-24 11:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/651#pullrequestreview-6038376930) · **reviewed** Independent verification at `5e19f489`: all 67 viewer streaming tests and 11 viewer studio tests passed. I also exercised the downloader over loopback HTTP with a shortened deadline and synthetic bytes. With nonempty body fragments arriving within each idle interval but taking longer than one interval in total, the base aborted and the PR returned the complete byte sequence. Both revisions still aborted a stalled response. AI-assisted testing.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/651/head:github-bot/gh-651'
git switch 'github-bot/gh-651'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-651'
git switch 'github-bot/gh-651'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-651'
git switch 'github-bot/gh-651'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-651'
git switch 'main'
git merge --squash 'github-bot/gh-651'
git switch 'main'
git merge --ff-only 'github-bot/gh-651'
git switch 'main'
git merge 'github-bot/gh-651'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.