Skip to content

fix(state): respect caller deadlines during writer contention - #1834

Draft
frahlg wants to merge 2 commits into
masterfrom
fix/myuplink-token-busy-20261025
Draft

frahlg wants to merge 2 commits into
masterfrom
fix/myuplink-token-busy-20261025

Conversation

@frahlg

@frahlg frahlg commented Oct 25, 2026

Copy link
Copy Markdown
Member

Follow-up to #1826. Its writer-first reservation fixes the immediate SQLite BUSY upgrade, but the SQLite busy handler can still keep a short-deadline caller waiting. On exact master 8e33174ed391c8e5f4886ab11959b4d962617fd5, the new parent-deadline regression fails after 5.04 seconds with a 150 ms parent deadline. The token/binding cases already pass on that base.

This PR keeps the writer-first reservation and bounds the wait by the caller's existing deadline:

  • Temporarily set busy_timeout=0 on the leased connection and wait in Go within the same five-second call budget and parent deadline.
  • Retry only the zero-row writer reservation on primary SQLITE_BUSY (5). Run the caller's transaction callback once.
  • Use FULL sync for the write, then restore both prior connection settings. Discard the connection if restoration fails.
  • Keep atomic credential binding, revision conflicts and rollback behavior. Add no schema, queue, service, setting or driver change.

Validation

  • Red on unchanged master 8e33174: the short-deadline regression fails; the four token test result nodes pass.
  • Green after this change: all seven new test functions and their subtests pass (10 result nodes).
  • make verify: PASS, including the final verify: vet + test + build clean marker. The earlier report-clock failures are resolved on this tested base by test(stats): pin the relay client's clock to the fake gateway's #1825; the old failed runs remain historical evidence.
  • cd go && go test -race -json ./internal/state -count=1: 494 PASS, 0 FAIL, 8 existing SKIP.

The regression set covers concurrent rename commit/rollback, missing settings, reservation before callback reads, short cancellation, the five-second budget, FULL sync and pooled-connection restoration, atomic rollback, revision conflicts and non-BUSY errors. No expectations or skip lists changed. The final Go source matches the tested source; only changeset wording changed while those checks ran.

The tested base is 8e33174. Master advanced to 69700f4 before publication through unrelated driver/charging changes; those changes do not touch the three files in this PR. Fresh open-PR file checks found no overlap. The branch preserves the original local fix commit 5684409 and integrates the merged #1826 rather than replacing its tests.

Handoff and limits

This is a draft for review. Local SQLite tests do not establish the historical box event's exact SQL step or lock owner, successful persistence of that rotated token, or durable recovery across restart. No box read/change, installation, merge or release was performed for this handoff. The separate MyUplink retry change in srcfl/device-drivers#193 is merged; it still needs its own bundled-release and field evidence.

Continue the independent read investigations in #1830 (forecast calibration) and #1831 (savings cancellation). Existing work remains separate: #1763 (published EV fix), #1554 (history write deadlines), #1556 (migration preservation), #1254 (offline converter), #1530 and srcfl/ftw-web#17 (stable guide/site drafts). This PR clears none of their evidence gates or the local stable holds.

Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant