Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race in parallel test with RequestLogger middleware #2476

Closed
rugleb opened this issue Jul 11, 2023 · 0 comments · Fixed by #2477
Closed

Data race in parallel test with RequestLogger middleware #2476

rugleb opened this issue Jul 11, 2023 · 0 comments · Fixed by #2477

Comments

@rugleb
Copy link

rugleb commented Jul 11, 2023

Issue Description

I get a WARNING: DATA RACE when running parallel tests with the "-race" flag in RequestLoggerConfig.

Checklist

  • [+] Dependencies installed
  • [+] No typos
  • [+] Searched existing issues and docs

Expected behaviour

No data race in parallel tests

Actual behaviour

Data race in parallel tests

Steps to reproduce

Save code below to bug_test.go:

package bug

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

	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func New() *echo.Echo {
	e := echo.New()
	e.Pre(
		middleware.RequestLoggerWithConfig(
			middleware.RequestLoggerConfig{},  // just example
		),
	)
	return e
}

func TestB(t *testing.T) {
	t.Parallel()

	req := httptest.NewRequest(http.MethodGet, "/", nil)
	res := httptest.NewRecorder()
	New().ServeHTTP(res, req)
}

func TestA(t *testing.T) {
	t.Parallel()

	req := httptest.NewRequest(http.MethodGet, "/", nil)
	res := httptest.NewRecorder()
	New().ServeHTTP(res, req)
}

Run: go test -race bug_test.go.

Working code to debug

See "Steps to reproduce".

Version/commit

v4.10.2

Reason/Solution

RequestLoggerConfig override global now which defined in rate_limiter.go without sync. I think this operation must be safe.

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 a pull request may close this issue.

1 participant