fix: eliminate production panics in client decoder and server startup - #322
Merged
Conversation
- replace unwrap() in scan_page decoder with ok_or_else returns (C1) - replace nth(3).unwrap() in slowlog decoder with ok_or_else (C2) - log a warning instead of silently zeroing TTLs when system clock is before unix epoch for EXAT/PXAT commands (C3) - replace split_first().expect() with let-else after is_empty guard (C4) - convert spawn_blocking expects to logged error + return in worker thread body; collect thread spawns as Result and propagate via ? (C5)
Merged
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
static analysis found five reachable panics in production paths. this pr addresses all of them with minimal, focused changes.
C1 — scan decoder unwrap (
ember-client/src/commands.rs): twoiter.next().unwrap()calls after a length check. while logically safe, replaced withok_or_elseto surface any protocol violation as a properClientErrorrather than a panic.C2 — slowlog decoder unwrap (same file):
entry.into_iter().nth(3).unwrap()after alen < 4guard. same pattern — replaced withok_or_else.C3 — silent TTL zeroing (
execute.rs):SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default()silently producedDuration::ZEROon a misconfigured clock, causing EXAT/PXAT keys to expire immediately with no indication of why. now logs awarn!so operators know to check the system clock.C4 — split_first expect (
execute.rs):sets.split_first().expect("non-empty")was guarded byis_empty()above it, but relied on that relationship staying intact. replaced with alet-elsethat makes the guard local and obvious.C5 — worker thread and runtime spawning (
server.rs): two.expect()calls in the startup path. the runtime build failure (inside the thread) now logs an error and exits the thread gracefully instead of panicking the worker. the thread spawn failure is now collected asResultand propagated via?to the caller, giving a clean error instead of a process crash.what was tested
cargo build -p ember-server -p ember-client— cleancargo test -p ember-server -p ember-client— passes