🐛 bug: Prevent app.init mutex deadlock on panic#4366
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix mutex deadlock in app.init() due to panic handling
Prevent app.init mutex deadlock on panic
May 28, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4366 +/- ##
==========================================
+ Coverage 91.33% 91.38% +0.04%
==========================================
Files 132 132
Lines 13104 13105 +1
==========================================
+ Hits 11969 11976 +7
+ Misses 716 711 -5
+ Partials 419 418 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens App.init() against panic-induced deadlocks by making the init mutex unlock panic-safe while preserving the existing ordering where OnPostShutdown is registered only after the init lock is released.
Changes:
- Scope the
App.init()critical section in an inner function and usedefer app.mutex.Unlock()to ensure the mutex is always released, even ifinitServices()orViews.Load()panics. - Keep
OnPostShutdownregistration outside the critical section to preserve the prior lock-release ordering. - Add a regression test that forces a panic during a second
app.init()and verifies later route registration does not deadlock.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app.go | Makes app.init() mutex unlock panic-safe by scoping the lock and deferring Unlock() within an inner function. |
| app_test.go | Adds a test that reproduces the prior deadlock scenario (panic during init()), asserting route registration proceeds afterward. |
ReneWerner87
approved these changes
May 28, 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.
Description
app.init()manually releasedapp.mutex, so a panic during service or view initialization could leave the app permanently locked. This change makes the init critical section panic-safe without changing the existing post-init hook registration order.Locking fix
app.init()critical section inside a small inner function.defer app.mutex.Unlock()inside that scope so panics frominitServices()orViews.Load()cannot strand the mutex.OnPostShutdownis registered only after the init lock has been released.Regression coverage
Views.Load()to panic during a follow-upapp.init().app.Get(...)call does not block, covering the original deadlock path.Changes introduced
Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md