fix(cloudflare): harden varlock-wrangler FIFO server against CI races#743
Open
theoephraim wants to merge 1 commit into
Open
fix(cloudflare): harden varlock-wrangler FIFO server against CI races#743theoephraim wants to merge 1 commit into
theoephraim wants to merge 1 commit into
Conversation
Add a readiness handshake on a dedicated control pipe (fd 3) so the parent waits until the child has buffered content and is about to serve the FIFO before spawning downstream consumers like wrangler. This eliminates a race where wrangler could open the FIFO before the child was ready, observed in Linux/Docker CI as `The contents of "/tmp/varlock-secrets-..." is not valid` (#739). Additional hardening: - Forward child stderr to parent so write failures are no longer swallowed by a silent process.exit. - Surface child write errors with iteration number + error code via the control pipe. - Fix UTF-8 corruption when stdin chunks split a multi-byte character (use Buffer.concat instead of string +=). The startServing() API becomes async; all call sites in handleDeploy, handleTypes, and handleDev await readiness before consumers start.
Contributor
|
The changes in this PR will be included in the next version bump.
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Adds a readiness handshake to the FIFO server child used by
varlock-wrangler deploy/versions upload/dev/typesso the parent doesn't spawn the downstream consumer (wrangler) before the child is actually serving content. Closes the most likely cause of #739.The reported symptom in Linux/Docker CI is:
That error fires in wrangler's
parseBulkInputToObject(insecret/index.ts) only whenreadFileSyncreturns content that is neither valid JSON nor parseable as a non-empty dotenv file — i.e. empty or truncated. The most plausible path to that under our FIFO-based flow is a race where wrangler opens the FIFO before the FIFO server child has even reached its firstwriteFileSynccall.Changes
ready\nafter buffering content and immediately before its first (blocking)writeFileSync.startServing()returns a promise that resolves on that signal.handleDeploy,handleTypes, andhandleDevawait it before spawning wrangler.handle.update()in dev mode also awaits, so wrangler restarts don't race against the new FIFO server.catch { process.exit(); }on write failure, hiding any EPIPE/ENXIO/etc. Now write errors are sent back to the parent over fd 3 (with iteration number + error code) and written to the child's stderr, which is forwarded to the parent's stderr.content += don aBuffercallstoString()per chunk; if a chunk boundary splits a multi-byte character, the result is silently corrupted. Switched toBuffer.concat(chunks).toString('utf8').Why this is probably it (without a local repro)
I tried to reproduce on agent-ci with the same overlay-FS environment the reporter uses — 64KB payload, 13 chunks, repeated runs — and could not. The race condition this PR fixes is timing-sensitive and depends on factors that can vary between CI environments (CPU pressure, container scheduling, base image). The child error surfacing is just as important as the handshake: if this PR doesn't fully resolve the issue, the reporter's next failure will now produce a usable error log instead of silently bad data.
Test plan
bun run --filter @varlock/cloudflare-integration buildpasses (DTS clean)bun run test:cloudflarein framework-tests: 66/66 passing (includes wrangler dev path which exercises the FIFO+update flow)bun run lintcleanvarlock-wrangler deploy --dry-runwith a 13-chunk (~65KB)__VARLOCK_ENVpayload completes cleanly. NewFIFO serve readydebug log appears at the expected point.