Urgent.News

What's breaking now, across thousands of outlets.

Tech

Worker Package Build Fix: Include Matching WASM Binary to Ensure Complete, Verifiable Deployments

Introduction: The Missing WASM Binary Imagine assembling a precision tool, meticulously tightening every screw, only to realize the core component—the blade—was left on the workbench. This is the essence of the problem uncovered in a recent Worker package build: the JS loader was vendored, but the matching WASM binary was overlooked. The immediate consequence? A package that appeared complete,…

The problem surfaced when workers were built: the loader was included, yet the WASM binary was absent. At first glance, the package looked complete, thanks to a workspace that hadn't been cleaned, but actually, it was incomplete and unverifiable. The cause was found in two asynchronous build processes: one for the JS loader and another for the WASM binary.

The loader was prepared first, while the binary, generated separately through an Emscripten step, was not copied over. This created a gap in synchronization, where the binary’s absence went unnoticed. A workspace with remnants from a previous build further disguised the issue, as the old binary remained, giving the impression that the package was complete.

The repercussions were two-fold: the package's integrity was compromised, and it couldn't be reliably reproduced. This had serious implications - if the binary was missing or didn't match, the runtime would fail, leading to an unreliable deployment that remained undetected until it ran. Here’s how the failure unfolded: 1. Build Steps Were Separate: The loader and binary were created in different steps.

The Worker build copied the loader but ignored the binary. 2. Workspace Masking: A previous build left its binary behind, making the package seem complete. 3. No Checks: There were no mechanisms to ensure both artifacts were present and consistent, allowing mismatched or missing binaries to go undetected. When deployed, the package had an incomplete runtime, resulting in unpredictable behavior or crashes.

To fix this, the strategy was simple but crucial: treat the loader and binary as one unit. This required: 1. Synchronized Builds: The Emscripten step now generates both the loader and binary together, ensuring they are ready at the same time. 2. Explicit Copying: The Worker build explicitly moves both files to the dist directory, removing reliance on the workspace's state.

3. Verification Checks: The build now hashes both the loader and the binary, and it fails if they don't match. Here’s how the verification works: it reads the expected hashes for both the loader and the binary, computes the actual hashes of the files being deployed, and compares them. If there’s a mismatch, it throws an error indicating a checksum mismatch.

The question arises: should the WASM binary be committed for reproducible installs, or should it be rebuilt in CI and verified there? The recommendation is to rebuild in CI and verify the hash there. This approach keeps the repository clean, ensures the binaries are always up-to-date, and avoids the problem of outdated binaries due to changes in the build process.

However, it requires a CI pipeline with pinned dependencies to prevent hash mismatches caused by external changes. In summary, if your build process generates paired artifacts, treat them as a single release unit and verify their consistency. A dirty workspace isn't a safety net—it's a liability. By synchronizing your build steps and enforcing these checks, you ensure that your deployments are complete, verifiable, and reliable.

The root cause of the issue was a combination of asynchronous build steps, a dirty workspace, and insufficient verification mechanisms. By addressing these areas, the missing WASM binary issue in Worker package builds can be resolved, ensuring that deployments are both complete and reliable.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Building a real-time global leaderboard with Supabase Realtime

A leaderboard looks trivial until it has to be live, global, and correct under load: rank the world by score, push every change to every connected client, and never melt the database doing it.

  • Use an append-only events table and scores aggregate table for consistency.
  • Compute rank using window function without full table scan.
  • Broadcast top 100 scores to clients for real-time updates.

REST vs GraphQL in Practice

The Real Trade-offs After building APIs with both REST and GraphQL, I've learned that the choice isn't about which is "better" but which fits your specific constraints.

More from Tuesday 18 August →