imroc / req

Simple Go HTTP client with Black Magic
https://req.cool
MIT License
4.12k stars 334 forks source link

fix: use correct context for dial #341

Closed ferhatelmas closed 2 months ago

ferhatelmas commented 2 months ago

It's lock protected and not safe for concurrent use. It should use previously read context. Otherwise, can panic under high concurrency.

imroc commented 2 months ago

The logic of the standard library is used here: https://github.com/golang/go/blob/go1.22.2/src/net/http/transport.go#L1485

If you think there is a problem, you can submit a PR to the upstream standard library

ferhatelmas commented 2 months ago

Standard library does the right thing. Merge is done wrong.

See the difference: https://github.com/imroc/req/commit/d0373d27487a0fac2a5005e258747bcccb5e44e8#diff-5982a4ca350449c8a5deba675bc4bc4bb0f1823c45e6c7ba0076cc6b159fef8fL1818 https://github.com/golang/go/blob/master/src/net/http/transport.go#L1510

imroc commented 2 months ago

Oh yeah, sorry I misunderstood before, this is a nice catch!

ferhatelmas commented 2 months ago

Is it possible to cut a new release for the fix?

imroc commented 2 months ago

Released in v3.43.2 @ferhatelmas