Skip to content

🐛 [Bug]: v3 ctx.Context() is cancelled upon creation  #3186

@gistart

Description

@gistart

Bug Description

Running app normally w/ Listen -- context is fine, so I can use it for my db queries.

fmt.Printf("%+v // %+v\n", c.Context(), c.Context().Err())
// #0000000100000001 - 127.0.0.1:8081<->127.0.0.1:48162 - GET http://0.0.0.0:8081/test // <nil>

Running a test on the same app -- and context is cancelled upon creation

fmt.Printf("%+v // %+v\n", c.Context(), c.Context().Err())
// #0000000100000001 - 0.0.0.0:0<->0.0.0.0:0 - GET http://example.com/test // context canceled

Screenshot from 2024-11-05 00-38-18

How to Reproduce

  1. Create new app
  2. Create any handler
  3. Print context and it's Err()

See code snippet below

Expected Behavior

Context in both prod and test should be initialized as not Done, w/o any errors.

Fiber Version

v3.0.0-beta.3

Code Snippet (optional)

// main.go

package main

import (
	"fmt"

	"github.com/gofiber/fiber/v3"
)

func main() {
	app := newApp()
	app.Listen(":8081")
}

func newApp() *fiber.App {
	app := fiber.New()
	app.Get("/test", func(c fiber.Ctx) error {
		fmt.Printf("%+v // %+v\n", c.Context(), c.Context().Err())
		return c.SendString("ok")
	})
	return app
}

// main_test.go

package main

import (
	"net/http/httptest"
	"testing"
)

func TestMain(t *testing.T) {
	app := newApp()

	req := httptest.NewRequest("GET", "/test", nil)
	_, err := app.Test(req, -1)
	if err != nil {
		t.Fatal(err)
	}
}

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions