Repository navigation
fix(server): a request keeps its own copy of its key label - #560
Merged
Merged
Conversation
Owner
jschmied
pushed a commit
to jschmied/TensorFold
that referenced
this pull request
Oct 10, 2026
Closed
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
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.
What this changes
Store.matchinzig/src/server/auth.zigreturned a key file entry's label as a slice into the store'sfile_arena. The request keeps that slice inconn.key_labeland reads it again, outside the store's mutex, when its response starts: for the access line (log.request) and the/metricsrequest count (countReply), both fromstartResponse, and forsendError's log line. For a reply that is not streamed, that is after the route has run. In between, any other request,/healthincluded, callsmatch, andrefreshcan free that arena.refreshrereads the key file when it changed (an edit or an atomic rename, noticed at most once a second) and, after SIGHUP, at the nextmatchwhether or not it changed. A successful reread frees the old arena (auth.zig:130), and a refused one (the file removed, or made readable by others) frees it as well (auth.zig:157). The request that was authenticated by a file key then reads freed memory when it answers.matchnow copies the label into the request's arena while it holds the mutex, so the label lives as long as the request. Labels from--api-keyandTENSORFOLD_API_KEYare copied the same way, a few bytes per request. If the copy cannot be allocated, the request counts as carrying no key, so a gated route answers 401. The copy is never read after its arena is reset: that happens when the connection goes back to read its next request (server.zig:226), andreadRequestthen clearskey_labelfirst, before any reply that could log it (http_conn.zig:168). The metrics table keeps its own copy of the key (metrics.zig:79).Receipt
78ee0f42, fix2193d145, Zig 0.17.0, Linux x86_64 under WSL2. No GPU and no model are needed.bash zig/tests/server/zig_test.sh(the server module, then the engine seam) passes 74 and 28 tests with this change; the base passes 73 and 28.zig build testpasses 17/17 steps and 78/78 tests; on Linux it does not include the server module.match:_ = label;, it fails on its own on the base, also with a segmentation fault, at line 334 (expectEqualStrings("ci", kept)). A probe that is not part of this change goes through the access line's own reader: it keeps the label on aConn, setsreload_requestedas SIGHUP does with the file unchanged, lets a request without a key callmatch, and reads the label back withlog.keySuffix. It passes with the fix; with only the copy reverted it segfaults inlabel_suffix(log.zig:84).python3 tools/zig/lean_check.pyreports 786 files and 510 problems on the base, and the same list with this change.zig fmt --check build.zig zig, the check CI runs, passes. The server tests compile foraarch64-macoswith-mcpu apple_m1 --test-no-exec; this is a compile check, not a macOS test run.auth.zig. The two merge without conflicts, and the server tests pass on the merge (77 and 28).