fix: P9 β consolidate lock hoist, Condvar backpressure, TOCTOU hardening - #986
Merged
Merged
Conversation
β¦ing, saturating overflow consolidate.rs: - Hoist index write lock outside dedup loop β acquire once, save once instead of lock+save per pair (N pairs β 1 lock + 1 save) server/main.rs: - Replace spin-yield backpressure with Condvar-based semaphore - Thread park instead of CPU burn under load - Preserve spawn-error slot release semantics vector.rs: - load_or_create: atomic file create via OpenOptions::create_new eliminates TOCTOU race (exists+write β create_new) - key mapping: replace exists()+read() with match on read_to_string (eliminates TOCTOU between check and read) - saturating_add(1) for next_key to prevent u64 overflow panic Test: 476 pass, 0 fail | Clippy: 0 warnings
| let mut index = self | ||
| .index | ||
| .write() | ||
| .map_err(|_| Error::lock("index write lock during consolidate"))?; |
π Cora AI Code Reviewβ Blocked β critical issues found. π΄ Error (1)
Review powered by cora-code Β· BYOK Β· MIT |
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
Performance and safety improvements addressing backlog items from cora re-scan analysis.
Why
These issues were identified during the P8 post-merge cora re-scan (163 findings) and represent the highest-impact backlog items:
yield_now()spin loop instead of parking threadsnext_key + 1could panic on u64 overflow (unlikely but undefined behavior)Changes
consolidate.rsβ Lock hoist + single saveindex.save()after all removals completeserver/main.rsβ Condvar backpressure(Mutex<usize>, Condvar)pairnotify_one()on completion to wake the accept loopvector.rsβ TOCTOU + overflow hardeningload_or_create:OpenOptions::create_new(true)replacesif !exists() { write() }β atomic file creation eliminates racematch read_to_string()replacesif exists() { read() }β eliminates check-then-read racesaturating_add(1)fornext_keyprevents u64 overflow panic at max valueTesting