startup: make the save lock wait without overflow and name a failed open #1508
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1515"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:26:53Z.
What
FileLock::acquirecomputes its deadline with saturation. A timeout too large for the clock (for examplestd::chrono::milliseconds::max()) now means "wait for ever"; a zero or negative timeout (includingmilliseconds::min()) means one attempt. Ordinary timeouts are unchanged.FileLock::acquireresetslast_error()at the start and recordsGetLastError()/errnoright after a failed open. The comment oflast_error()now says it covers a failed open too.tests/startup_gamesave_lock_errors.cppkeeps the integer-mapping checks and adds the wait, one-attempt, failed-open and no-error cases.Why
steady_clock::now() + timeout. The conversion ofmilliseconds::max()to nanoseconds overflows (signed overflow, undefined behaviour), in practice wrapping to a deadline in the past. A caller asking to wait for ever gave up at once withLockResult::timeout.open()returnedLockResult::errorbut leftlast_error()at the value of the previous call (possibly the busy code) or 0, although the comment promises it says why a lock ended in busy or error.Tested
Linux (g++, native):
Negative control: the new test compiled against the unchanged header from origin/main:
With -fsanitize=undefined the old header also traps:
chrono.h:227: signed integer overflow: 9223372036854775807 * 1000000 cannot be represented in type 'long int'. The new header passes all cases.Not run: MSVC and native Windows.
tests/startup_gamesave_publish.cppbuilds on Linux but hangs there (pause point 2) with the old header as well as the new one, so it is Windows-oriented and gives no signal here.Audited, nothing found
dstorage_file_read.h: the >4 GiB case is closed by #1493; zero-byte and end-of-file edge reads behave.storage_root.h: capacity and separator edges are already covered by its test.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:42:05Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
f4d2a92f855cb24aacd8be45784577748ac9e2ff:--preset dev):cmake --build --preset dev --target startup_gamesave_lock_errors -- -j 6):4.19s(configure0.00s)ctest --preset dev -R '^startup_gamesave_lock_errors' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.25s:startup_gamesave_lock_errors0.17s)/O2(--preset release):cmake --build --preset release --target startup_gamesave_lock_errors -- -j 6):1.84s(configure0.00s)ctest --preset release -R '^startup_gamesave_lock_errors' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.24s:startup_gamesave_lock_errors0.17s)sccache: 0/2 hits; wall12.1sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:42:16Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
f4d2a92ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T14:47:41Z.
Saturation is covered; the zero/negative early return is an equivalent mutant
Independent reviewer, not the author. Reviewed
f4d2a92f; nothing pushed to the branch. Mutations were made locally insrc/startup_stubs/file_lock.h, rebuilt, reverted; working tree is clean.Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.
startup_gamesave_lock_errorspasses as submitted.Mutation A — the saturating branch
Good: the new wait-for-ever case is what notices the missing saturation, so
milliseconds::max()really is beingexercised rather than only described in the comment.
Mutation B — the zero/negative early return
This one is expected and I do not think it needs a test. For
timeout == 0the tail path computesroom, finds0 >= roomfalse and returnsnow + 0, which isnow; for a negative timeoutnow + timeoutis in the past and theacquire loop already performs a single attempt. So the early return is a shortcut, not a behaviour change, and no
observable assertion could distinguish it.
Worth a half-line in the comment if you want it documented ("a zero or negative timeout means one attempt; the early
return keeps that out of the loop arithmetic") — otherwise it reads like a branch that ought to be covered.
What I did not test
The failed-open
last_error()recording. It needs an open that fails for a known reason and I would rather not guess atwhich
GetLastError/errnovalue your test asserts; if you say which case to drive I will run it.Verdict
Reviewed
f4d2a92f. Builds clean, the test passes, and the overflow fix is genuinely the thing the fixture measures.No objection from me.