Skip to content

Fix: Full review 4.0.12 fixes part 1 - #256

Merged
rubenberttpingol merged 2 commits into
developfrom
fix/full-review-4-0-12-fixes
Oct 6, 2026
Merged

rubenberttpingol merged 2 commits into
developfrom
fix/full-review-4-0-12-fixes

Conversation

@rubenberttpingol

@rubenberttpingol rubenberttpingol commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #255

Fixes the ten P0 defects from the 4.0.12 full review, plus two defects found while testing them. Each one could lose proof of play, freeze or hang the player, break media on screen, or waste downloads.

Bugs fixed

Proof of play

  1. Stats were deleted when the upload to the CMS failed. submitStats() returned an error object on failure, which counts as true, so the caller deleted the batch.
    • Fix: it now resolves true only when the CMS confirms, and both callers (index.ts, transferCms.ts) check === true.
  2. Every unsent stat was wiped on startup. PoPStats ran DELETE FROM stats in its constructor, so a reboot, crash or update lost everything not yet sent.
    • Fix: only stats left open by the restart are dropped (StatsDB.deleteOpen()). Finished, unsent stats are kept and sent on the next collection.

Schedule loop

  1. Only the first normal layout played while an interrupt or SSP was scheduled. The loop that fills the hour with normal layouts never incremented index. A schedule with only interrupts threw a TypeError.
    • Fix: index is incremented. With no normal layouts, the interrupts play on their own.
  2. A duration of 0 or a missing duration hung the main process. The share-of-voice loops never reached their target and grew an array until V8 threw Invalid array length. That took up to 2 GB of memory and several seconds. SSP without an average ad duration did the same.
    • Fix: the new loopDuration() (shareOfVoice.ts) counts a missing, zero or NaN duration as 60 s, but only when the hour is divided up; playback length is unchanged. SSP is only added when an ad duration is known.
  3. One exception during assessment froze the screen until restart. isAssessingLayouts / isAssessingOverlays stayed true, so every later assessment was skipped. A layout with an empty geoLocation was enough to trigger it.
    • Fix: both assessments run in try/finally, and a geofence that can't be read leaves that layout out.

Main process

  1. A new screenshot timer was started on every collection and the old one was never cleared, so timers piled up without limit.
    • Fix: the timer is only rebuilt when the CMS changes the interval, and the old one is always cleared first.
  2. Every renderer reload restarted the player. A reload after a refresh command or a change of CMS re-registered every XMDS, XMR and SSP handler and timer. Commands then ran, and stats were submitted, once per reload.
    • Fix: run() starts the player once. A later call only triggers a collection, so a changed CMS is still picked up straight away.

Downloads

  1. Downloaded files were never checked against their MD5. A cut-off transfer, or a captive-portal page sent with a 200, was stored as a success and never fetched again.
    • Fix: the MD5 is computed while the file streams and compared with the MD5 the CMS lists. A mismatch fails the download, and it is retried on the next collection.
  2. A failed update deleted the copy that was playing. The error path removed the file at its final path.
    • Fix: downloads go to a unique .part file and are renamed into place only once complete and verified. A failed update leaves the old file and its database row as they were, so it keeps playing until the update succeeds.
  3. Whole files were held in memory and written synchronously (arraybuffer + writeFileSync). Memory grew by the size of the file being downloaded, and the write blocked the main process.
    • Fix: files are streamed to disk.
  4. The same files were downloaded twice at the same time. collect() does not wait for the downloads it starts, so a collection could arrive while a download pass was still running, fetch the list again and start a second pass. On a first boot against a real CMS, 3 videos downloaded twice at once and 4 downloads ran against a limit of 2.
    • Fix: one pass over the required files runs at a time. A list that arrives during a pass waits, and only the newest one is kept. downloadFile() also waits for a download already running for the same file instead of starting another.

XMDS errors

  1. Some CMS error bodies caused an unhandled rejection. Error.parse() runs in a callback nothing awaits, and read the SOAP fault without checking each step. An empty body (a typical proxy 500 or 502), a well-formed non-SOAP page, or an envelope without a Fault all threw.
    • Fix: the fault is read step by step. A body that is not a fault becomes the message, as plain text already did, and anything else is caught and logged.

Testing

Every bug was reproduced against the unchanged code before it was fixed, using a harness kept outside the repo. The harness runs the real main-process modules, including all of src/main/index.ts, with Electron stubbed out.

Synthetic checks: all ten reproduce on develop, and none reproduce on this branch. Normal cases for downloads and the schedule loop still pass.

Against a real CMS (develop.xibo.co.uk, a test display with 5 normal layouts, a 1500 s share-of-voice interrupt, a 1 minute screenshot interval and stats on). Failures were injected one at a time through a proxy that otherwise passed every reply through unchanged.

develop this branch
1 3 stats → 0 after a 503 kept, then sent (CMS true)
2 2 unsent stats → 0 after restart kept, then sent (CMS true)
3 4 of 5 normal layouts never played all 5 play, interrupt gets 25 min
4 3.2 s stall, 980 MB, crash, stuck 10 ms, recovers
5 assessment stuck for good layout skipped, recovers
6 6 screenshot timers after 6 collections 1
7 listeners 1 → 3 after 2 reloads unchanged
8 portal page stored as success rejected, correct file stored
9 playing image deleted old image kept
11 91 download requests for 86 files, 3 videos downloaded twice at once 86 requests for 86 files
12 empty, HTML and fault-less SOAP bodies: unhandled rejection handled; real SOAP faults still raised

All 86 files the CMS listed (media, layouts, fonts, bundle.min.js, fonts.css, HTML package) pass the new MD5 check.

The real CMS content is too small (largest file 6.8 MB) to show #10. On a 600 MB synthetic download, memory growth fell from 620 MB to 41 MB.

Notes

  • Startup isn't retried: if the first run() throws partway through, a renderer reload no longer retries the startup. Before, a reload re-ran it but duplicated every handler that had already registered.
  • A .part file can be left behind if the player stops mid-download. It is not served or used, and is replaced on the next attempt.
  • Not fixed here: handleError()'s "not authorised" check compares the message before the async parse has filled it in, so it never fires. It has no effect today: the one caller that relies on it gets its error from handleXmdsError, which is awaited.

@rubenberttpingol rubenberttpingol self-assigned this Oct 5, 2026
@rubenberttpingol
rubenberttpingol requested review from dasgarner and nadzpogi and removed request for dasgarner October 5, 2026 06:29
@rubenberttpingol rubenberttpingol changed the title Fix: Full review 4.0.12 fixes Fix: Full review 4.0.12 fixes part 1 Oct 5, 2026
@rubenberttpingol
rubenberttpingol merged commit 987848d into develop Oct 6, 2026
1 check passed
@rubenberttpingol
rubenberttpingol deleted the fix/full-review-4-0-12-fixes branch October 6, 2026 11:05
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full review 4.0.12 fixes part1

2 participants