Skip to content

fix: eliminate production panics in client decoder and server startup - #322

Merged
kacy merged 1 commit into
mainfrom
fix/critical-panics
Feb 27, 2026
Merged

fix: eliminate production panics in client decoder and server startup#322
kacy merged 1 commit into
mainfrom
fix/critical-panics

Conversation

@kacy

@kacy kacy commented Feb 27, 2026

Copy link
Copy Markdown
Owner

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): two iter.next().unwrap() calls after a length check. while logically safe, replaced with ok_or_else to surface any protocol violation as a proper ClientError rather than a panic.

C2 — slowlog decoder unwrap (same file): entry.into_iter().nth(3).unwrap() after a len < 4 guard. same pattern — replaced with ok_or_else.

C3 — silent TTL zeroing (execute.rs): SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default() silently produced Duration::ZERO on a misconfigured clock, causing EXAT/PXAT keys to expire immediately with no indication of why. now logs a warn! so operators know to check the system clock.

C4 — split_first expect (execute.rs): sets.split_first().expect("non-empty") was guarded by is_empty() above it, but relied on that relationship staying intact. replaced with a let-else that 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 as Result and 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 — clean
  • cargo test -p ember-server -p ember-client — passes

- 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)
@kacy
kacy merged commit d916859 into main Feb 27, 2026
4 of 7 checks passed
@kacy
kacy deleted the fix/critical-panics branch February 27, 2026 01:25
@kacy kacy mentioned this pull request Feb 27, 2026
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