Skip to content

🐛 bug: Handle panics in client execFunc without crashing callers#4365

Merged
ReneWerner87 merged 2 commits into
mainfrom
copilot/fix-panic-recovery-in-goroutine
May 28, 2026
Merged

🐛 bug: Handle panics in client execFunc without crashing callers#4365
ReneWerner87 merged 2 commits into
mainfrom
copilot/fix-panic-recovery-in-goroutine

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2026

Description

client.execFunc() launched request execution in a goroutine without panic recovery. A panic from the transport path could terminate the process and leave the caller blocked waiting on pooled channels.

Changes introduced

  • Panic containment in execFunc

    • Add a recover() path around the goroutine body in client/core.go.
    • Convert panics into client panic: ... errors sent through errChan so callers fail normally instead of crashing.
  • Pool/resource safety

    • Release any partially acquired Response before reporting the panic.
    • Preserve the existing channel-drain / timeout behavior so pooled channels are not left in a bad state.
  • Regression coverage

    • Add a focused client test using a panicking transport to verify execFunc() returns an error and no response.
defer func() {
	if r := recover(); r != nil {
		if resp != nil {
			ReleaseResponse(resp)
		}
		errChan <- fmt.Errorf("client panic: %v", r)
	}
}()
  • Benchmarks: No benchmark impact; change is on an exceptional panic path.
  • Documentation Update: No docs changes required.
  • Changelog/What's New: Not added.
  • Migration Guide: Not needed; behavior changes only for panic cases.
  • API Alignment with Express: Not applicable.
  • API Longevity: Keeps existing client API intact; panics are surfaced as regular errors.
  • Examples: Added a regression test covering a panicking transport.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

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

Copilot AI changed the title [WIP] Fix panic recovery in execFunc goroutine for Fiber HTTP client Handle panics in client execFunc without crashing callers May 28, 2026
Copilot finished work on behalf of gaby May 28, 2026 04:14
Copilot AI requested a review from gaby May 28, 2026 04:14
@ReneWerner87 ReneWerner87 added this to v3 May 28, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 28, 2026
@gaby gaby marked this pull request as ready for review May 28, 2026 04:29
@gaby gaby requested a review from a team as a code owner May 28, 2026 04:29
@gaby gaby changed the title Handle panics in client execFunc without crashing callers 🐛 bug: Handle panics in client execFunc without crashing callers May 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (e5e93e6) to head (bedaffc).

Files with missing lines Patch % Lines
client/core.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4365      +/-   ##
==========================================
- Coverage   91.39%   91.33%   -0.06%     
==========================================
  Files         132      132              
  Lines       13098    13104       +6     
==========================================
- Hits        11971    11969       -2     
- Misses        710      716       +6     
- Partials      417      419       +2     
Flag Coverage Δ
unittests 91.33% <71.42%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Fiber client execution path by containing panics raised during asynchronous request execution and returning them as normal client errors instead of allowing goroutine panics to crash the process.

Changes:

  • Adds panic recovery in client.execFunc() and reports recovered panics through the existing error channel.
  • Releases any partially acquired client Response during panic recovery.
  • Adds regression coverage with a panicking transport implementation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
client/core.go Adds panic recovery and panic-to-error conversion inside the request execution goroutine.
client/core_test.go Adds a test transport that panics and verifies execFunc() returns an error with no response.

@ReneWerner87 ReneWerner87 merged commit e0b4946 into main May 28, 2026
28 of 29 checks passed
@ReneWerner87 ReneWerner87 deleted the copilot/fix-panic-recovery-in-goroutine branch May 28, 2026 05:31
@github-project-automation github-project-automation Bot moved this to Done in v3 May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: Client execFunc goroutine has no panic recovery — crash on fasthttp panic

4 participants