Skip to content

fix(memory): recover from panics during mission export#161

Merged
fank merged 2 commits intomainfrom
fix/export-panic-recovery
Apr 11, 2026
Merged

fix(memory): recover from panics during mission export#161
fank merged 2 commits intomainfrom
fix/export-panic-recovery

Conversation

@fank
Copy link
Copy Markdown
Member

@fank fank commented Apr 11, 2026

Summary

  • memory.Backend.EndMission now catches panics from the builder or gzip encoder and converts them to a returned error.
  • Logs the stack trace at ERROR level so a panic still leaves a forensic trail.
  • Does not attempt to catch runtime.throw / OOM — those are a kernel/container problem, not a panic.

Why

Previously any recoverable panic during buildExportUnlocked or writeGzipJSON would propagate straight out of the sync :MISSION:SAVE: handler and kill the ArmA host. Even once the handler is async (see #159), the worker goroutine still needs a clean error return instead of an unrecovered panic — the new :MISSION:SAVED: callback path relies on EndMission returning an error rather than panicking.

Test plan

  • go test ./internal/storage/memory/...
  • New test TestEndMission_RecoversFromBuildPanic exercises the recover path — verified to panic before the fix and return a descriptive error after.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces panic recovery in the EndMission method of the memory storage backend to prevent host process crashes during mission export, along with a corresponding test case. The review feedback correctly identifies that the current implementation leaves the backend in an inconsistent state when a panic occurs, as the necessary cleanup and state reset logic are bypassed.

Comment thread internal/storage/memory/memory.go Outdated
@github-actions
Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/extension/v5/internal/storage/memory 99.24% (+0.02%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/extension/v5/internal/storage/memory/memory.go 100.00% (ø) 227 (+6) 227 (+6) 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/extension/v5/internal/storage/memory/memory_test.go

@fank fank merged commit c97340f into main Apr 11, 2026
3 checks passed
@fank fank deleted the fix/export-panic-recovery branch April 11, 2026 22:04
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