Skip to content

🐛 bug: Fix Test method returning empty response on timeout#4063

Merged
ReneWerner87 merged 6 commits intomainfrom
copilot/fix-fiber-empty-response
Feb 8, 2026
Merged

🐛 bug: Fix Test method returning empty response on timeout#4063
ReneWerner87 merged 6 commits intomainfrom
copilot/fix-fiber-empty-response

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Description

The app.Test() method returns "test: got empty response" errors when timeouts occur, breaking tests that worked in v2. Root cause: connection closes on timeout before ServeConn finishes writing the response, leaving the read buffer empty.

Changes introduced

Core Fix (app.go)
Modified timeout handling in Test():

  • FailOnTimeout: true → closes connection, returns timeout error (unchanged)
  • FailOnTimeout: false → waits up to 1 additional second for handler to complete, preventing indefinite blocking while allowing handlers to finish
// Before: connection closed regardless of FailOnTimeout value
case <-time.After(cfg.Timeout):
    conn.Close()
    if cfg.FailOnTimeout {
        return nil, os.ErrDeadlineExceeded
    }

// After: connection only closed when failing on timeout
case <-time.After(cfg.Timeout):
    if cfg.FailOnTimeout {
        conn.Close()
        return nil, os.ErrDeadlineExceeded
    }
    // Wait up to 1 additional second for handler to complete
    select {
    case err = <-channel:
    case <-time.After(time.Second):
        conn.Close()
    }

Test Updates

  • Updated tests expecting interrupted behavior to explicitly set FailOnTimeout: true

  • Added regression tests verifying both timeout modes work correctly with explicit delays to ensure reliable timeout triggering

  • Fixed test that incorrectly expected empty response with FailOnTimeout: false

  • Reduced sleep/timeout values in tests from 1s/100ms to 50ms/10ms for faster test suite execution

  • Updated timeout test assertion to use ErrorIs for specific error validation

  • Benchmarks: No performance impact - same code paths, adds maximum 1 second wait when FailOnTimeout is false

  • Documentation Update: N/A - behavior now matches documented intent while preventing indefinite blocking

  • Changelog/What's New: Fixes Test method empty response error on timeout with bounded wait time

  • Migration Guide: No migration needed - fixes buggy behavior, breaking change only for tests relying on the bug

  • API Alignment with Express: N/A

  • API Longevity: Clarifies existing API semantics without changing signature, maintains timeout as safety limit

  • Examples: Test cases demonstrate both timeout modes with proper assertions

Type of change

  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

  • 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.
Original prompt

This section details on the original issue you should resolve

<issue_title>🐛 [Bug]: Fiber returns err: test: got empty</issue_title>
<issue_description>### Bug Description

The problem is that I currently get test: got empty response in my go fiber tests. The tests worked reliably in v2. I don't know exactly what the problem is because they are just normal fiber.Handler methods.

How to Reproduce

Steps to reproduce the behavior:

  1. Go to https://github.com/ether/etherpad-go
  2. Check out the branch feature/fiber-v3
  3. Open the test/api/groups/groups_api_test.go
  4. Run the tests. They all error out with nil pointers for response

Expected Behavior

They should run as expected and return the expected json structure.

Fiber Version

v3.0.0

Code Snippet (optional)

func CreateGroup(store *lib.InitStore) fiber.Handler {
	return func(c fiber.Ctx) error {
		groupId := "g." + utils.RandomString(16)
		err := store.Store.SaveGroup(groupId)
		if err != nil {
			return c.Status(500).JSON(errors.InternalServerError)
		}
		return c.JSON(GroupIDResponse{
			GroupID: groupId,
		})
	}
}

Test:

func testCreateGroupSuccess(t *testing.T, tsStore testutils.TestDataStore) {
	initStore := tsStore.ToInitStore()
	groups.Init(initStore)

	req := httptest.NewRequest("POST", "/admin/api/groups", nil)
	resp, err := initStore.C.Test(req, fiber.TestConfig{Timeout: 5000})

	assert.NoError(t, err)
	assert.Equal(t, 200, resp.StatusCode)

	var response groups.GroupIDResponse
	body, _ := io.ReadAll(resp.Body)
	_ = json.Unmarshal(body, &response)

	assert.NotEmpty(t, response.GroupID)
	assert.True(t, len(response.GroupID) > 2)
	assert.Equal(t, "g.", response.GroupID[:2])
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.</issue_description>

Comments on the Issue (you are @copilot in this section)

@gaby @SamTV12345 I'm trying to check but that code base is all over the place.
  • Are all test having this issue or some?
  • Have you tried running the app, to see if the routes work?</comment_new>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 7, 2026 21:05
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Fiber returns empty response in tests 🐛 bug: Fix Test method returning empty response on timeout Feb 7, 2026
Copilot AI requested a review from ReneWerner87 February 7, 2026 21:16
@gaby gaby marked this pull request as ready for review February 8, 2026 15:59
@gaby gaby requested a review from a team as a code owner February 8, 2026 15:59
@gaby gaby requested review from Copilot, efectn, gaby and sixcolors February 8, 2026 15:59
@ReneWerner87 ReneWerner87 added this to v3 Feb 8, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 8, 2026
Copy link
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

Fixes App.Test() returning ErrTestGotEmptyResponse when a timeout occurs by changing timeout handling so the connection isn’t closed when FailOnTimeout is false, allowing the handler to finish writing a response.

Changes:

  • Updated App.Test() timeout behavior to only close the test connection when FailOnTimeout is true.
  • Adjusted multiple “interrupted” tests to explicitly set FailOnTimeout: true and assert a timeout error.
  • Added/updated regression tests to validate behavior for small timeouts and FailOnTimeout modes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
app.go Changes timeout branch in App.Test() to avoid closing the connection when FailOnTimeout=false.
app_test.go Updates existing timeout test expectations and adds new regression tests for small-timeout behavior.
ctx_test.go Updates interrupted stream-writer test to assert timeout error when FailOnTimeout=true.
adapter_test.go Updates interrupted adaptor test to expect timeout error + nil response when FailOnTimeout=true.
middleware/adaptor/adaptor_test.go Same interrupted-test update for middleware adaptor package.

@gaby
Copy link
Member

gaby commented Feb 8, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 8, 2026

@copilot apply changes based on the comments in this thread

All review feedback has been addressed in commit a2594f7. Key changes:

  • Timeout handling now waits max 1 second when FailOnTimeout=false (prevents indefinite blocking)
  • Test sleep/timeout values reduced (faster test suite)
  • Added explicit handler delay in flaky test
  • Updated assertion to check specific error type

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.02%. Comparing base (b45321d) to head (a2594f7).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
app.go 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4063      +/-   ##
==========================================
- Coverage   91.11%   91.02%   -0.09%     
==========================================
  Files         119      119              
  Lines       11207    11211       +4     
==========================================
- Hits        10211    10205       -6     
- Misses        630      638       +8     
- Partials      366      368       +2     
Flag Coverage Δ
unittests 91.02% <60.00%> (-0.09%) ⬇️

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.

@ReneWerner87 ReneWerner87 merged commit f93613f into main Feb 8, 2026
17 of 18 checks passed
@ReneWerner87 ReneWerner87 deleted the copilot/fix-fiber-empty-response branch February 8, 2026 17:20
@github-project-automation github-project-automation bot moved this to Done in v3 Feb 8, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.1.0 Feb 27, 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]: Fiber returns err: test: got empty

4 participants