这是indexloc提供的服务,不要输入任何密码
Skip to content

Race condition detected in Huma v2.22.0 #552

@swsd2544

Description

@swsd2544

I detected race conditions with Huma v2.22.0, which did not occur with Huma v2.21.0.

==================
WARNING: DATA RACE
Read at 0x00c000ebc1c8 by goroutine 70:
  bytes.(*Buffer).Len()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/bytes/buffer.go:79 +0x50
  bytes.(*Buffer).grow()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/bytes/buffer.go:127 +0x38
  bytes.(*Buffer).ReadFrom()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/bytes/buffer.go:209 +0x5c
  io.copyBuffer()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/io/io.go:415 +0x1c8
  io.Copy()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/io/io.go:388 +0x4c
  github.com/danielgtaylor/huma/v2.Register[go.shape.struct { Body bitbucket.org/ltman/wx-auth/internal/verification.VerifyEmailSubmitRequestBody },go.shape.struct {}].func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/huma.go:1197 +0x1628
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.RequireSessionMiddleware.func5()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/middleware/require_session.go:24 +0x308
  github.com/danielgtaylor/huma/v2.Middlewares.Handler.Middlewares.chain.wrap.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/chain.go:16 +0x50
  github.com/danielgtaylor/huma/v2/adapters/humachi.(*chiAdapter).Handle.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/adapters/humachi/humachi.go:120 +0x148
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5.(*Mux).routeHTTP()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:459 +0x3f8
  github.com/go-chi/chi/v5.(*Mux).routeHTTP-fm()
      <autogenerated>:1 +0x4c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Handler.func4.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/httplog/v2@v2.1.1/httplog.go:111 +0x498
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.SessionClaimsMiddleware.func3.1()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/middleware/session_claims.go:58 +0x17c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Heartbeat.func2.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/heartbeat.go:21 +0x240
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Timeout.func1.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/timeout.go:44 +0x10c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5/middleware.Recoverer.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/recoverer.go:45 +0xb4
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5/middleware.RequestID.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/request_id.go:76 +0x260
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5.(*Mux).ServeHTTP()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:90 +0x4cc
  bitbucket.org/ltman/wx-auth/internal/http/tests.verifyEmailSubmitTestHelper()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/helpers_test.go:204 +0x3f8
  bitbucket.org/ltman/wx-auth/internal/http/tests.TestHTTP_PostRegisterPassword.func7()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/post_register_password_test.go:186 +0x1e4
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40

Previous write at 0x00c000ebc1c8 by goroutine 45:
  bytes.(*Buffer).Reset()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/bytes/buffer.go:108 +0x2174
  github.com/danielgtaylor/huma/v2.Register[go.shape.struct { Body bitbucket.org/ltman/wx-auth/internal/verification.VerifyEmailSubmitRequestBody },go.shape.struct {}].func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/huma.go:1303 +0x2158
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.RequireSessionMiddleware.func5()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/middleware/require_session.go:24 +0x308
  github.com/danielgtaylor/huma/v2.Middlewares.Handler.Middlewares.chain.wrap.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/chain.go:16 +0x50
  github.com/danielgtaylor/huma/v2/adapters/humachi.(*chiAdapter).Handle.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/danielgtaylor/huma/v2@v2.22.0/adapters/humachi/humachi.go:120 +0x148
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5.(*Mux).routeHTTP()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:459 +0x3f8
  github.com/go-chi/chi/v5.(*Mux).routeHTTP-fm()
      <autogenerated>:1 +0x4c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Handler.func4.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/httplog/v2@v2.1.1/httplog.go:111 +0x498
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.SessionClaimsMiddleware.func3.1()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/middleware/session_claims.go:58 +0x17c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Heartbeat.func2.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/heartbeat.go:21 +0x240
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  bitbucket.org/ltman/wx-auth/internal/http.NewRouter.Timeout.func1.1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/timeout.go:44 +0x10c
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5/middleware.Recoverer.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/recoverer.go:45 +0xb4
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5/middleware.RequestID.func1()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/middleware/request_id.go:76 +0x260
  net/http.HandlerFunc.ServeHTTP()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/net/http/server.go:2220 +0x48
  github.com/go-chi/chi/v5.(*Mux).ServeHTTP()
      /Users/siriwudhisawaidee/go/pkg/mod/github.com/go-chi/chi/v5@v5.1.0/mux.go:90 +0x4cc
  bitbucket.org/ltman/wx-auth/internal/http/tests.verifyEmailSubmitTestHelper()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/helpers_test.go:204 +0x3f8
  bitbucket.org/ltman/wx-auth/internal/http/tests.TestHTTP_PostSession.func1()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/post_session_test.go:33 +0xf4
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40

Goroutine 70 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x5e0
  bitbucket.org/ltman/wx-auth/internal/http/tests.TestHTTP_PostRegisterPassword()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/post_register_password_test.go:175 +0x338
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40

Goroutine 45 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x5e0
  bitbucket.org/ltman/wx-auth/internal/http/tests.TestHTTP_PostSession()
      /Users/siriwudhisawaidee/Documents/wealthx/wx-auth/internal/http/tests/post_session_test.go:25 +0x98
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40
==================

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions