Skip to content

Data race condition in the Alt-Svc cache #456

@andrei-cosmin

Description

@andrei-cosmin

I've been using the the req http client to handle concurrent requests.
Recently, I've started testing using the -race flag to spot data race errors and the stack trace points at a potential data race inside the req http client, specifically in the transport Transport inside checkAltSvc().

WARNING: DATA RACE
Read at 0x00c00024ba10 by goroutine 121:
  runtime.mapaccess1_faststr()
      /usr/local/go/src/internal/runtime/maps/runtime_faststr_swiss.go:103 +0x28c
  github.com/imroc/req/v3.(*Transport).checkAltSvc()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:849 +0x114
  github.com/imroc/req/v3.(*Transport).roundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:903 +0xd4
  github.com/imroc/req/v3.(*Transport).WrapRoundTrip.func1()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:209 +0x34
  github.com/imroc/req/v3.HttpRoundTripFunc.RoundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:175 +0x34
  github.com/imroc/req/v3.(*Client).ImpersonateChrome.(*Client).SetCommonPseudoHeaderOder.func2.1()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/client.go:935 +0x124
  github.com/imroc/req/v3.HttpRoundTripFunc.RoundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:175 +0x34
  github.com/imroc/req/v3.(*Client).ImpersonateChrome.(*Client).SetCommonHeaderOrder.func3.1()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/client.go:911 +0x124
  github.com/imroc/req/v3.HttpRoundTripFunc.RoundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/transport.go:175 +0x34
  github.com/imroc/req/v3.(*Transport).RoundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/roundtrip.go:22 +0x64
  net/http.send()
      /usr/local/go/src/net/http/client.go:259 +0x644
  net/http.(*Client).send()
      /usr/local/go/src/net/http/client.go:180 +0xf8
  net/http.(*Client).do()
      /usr/local/go/src/net/http/client.go:729 +0xd90
  net/http.(*Client).Do()
      /usr/local/go/src/net/http/client.go:587 +0xd6c
  github.com/imroc/req/v3.(*Client).roundTrip()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/client.go:1747 +0xd3c
  github.com/imroc/req/v3.(*Request).do()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/request.go:667 +0x220
  github.com/imroc/req/v3.(*Request).Do()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/request.go:635 +0x260
  github.com/imroc/req/v3.(*Request).Send()
      /Users/users/go/pkg/mod/github.com/imroc/req/v3@v3.54.0/request.go:725 +0xc0
  github.com/imroc/req/v3.(*Request).Post()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions