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

Open
opened 2026-11-26 20:18:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/651
Author: @kirigayakazima
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/viewer-chunk-idle-timeout


📝 Commits (1)

  • 5e19f48 viewer: reset chunk download deadline while body bytes stream (VIEWER-CHUNK-IDLE-TIMEOUT)

📊 Changes

2 files changed (+252 additions, -7 deletions)

View changed files

📝 tests/test_viewer_streaming.cjs (+173 -4)
📝 viewer/index.html (+79 -3)

📄 Description

Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129434586)

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/651 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/viewer-chunk-idle-timeout` --- ### 📝 Commits (1) - [`5e19f48`](https://github.com/ubiquitarianism/leonida/commit/5e19f4891003d45d27467604c49d865ebf61a4cc) viewer: reset chunk download deadline while body bytes stream (VIEWER-CHUNK-IDLE-TIMEOUT) ### 📊 Changes **2 files changed** (+252 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_viewer_streaming.cjs` (+173 -4) 📝 `viewer/index.html` (+79 -3) </details> ### 📄 Description Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129434586) ### What and why Follows up on @slauko's finding in [#14 (comment 7128949696)](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-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 - [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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#690
No description provided.