Closed pierDipi closed 5 months ago
rt1 := // ... create rountripper p1 := http.New(http.WithRoundTripper(rt1)) rt2 := // ... create rountripper p2 := http.New(http.WithRoundTripper(rt2)) // unexpected: // p1 has the same roundtripper rt2 as p2
This is caused by the use of the same underlying DefaultClient
DefaultClient
https://github.com/cloudevents/sdk-go/blob/4fb49a39a22b41c03d956996313995cf35ec0ac2/v2/protocol/http/protocol.go#L104-L110
This can also technically cause data races.
Workaround
Specify a different client for each Protocol using WithClient:
Protocol
WithClient
rt1 := // ... create rountripper p1 := http.New(http.WithClient(nethttp.Client{Transport: rt1})) rt2 := // ... create rountripper p2 := http.New(http.WithClient(nethttp.Client{Transport: rt2}))
@pierDipi thx for flagging this. Wondering if we can close this issue since you document a workaround?
This is caused by the use of the same underlying
DefaultClient
https://github.com/cloudevents/sdk-go/blob/4fb49a39a22b41c03d956996313995cf35ec0ac2/v2/protocol/http/protocol.go#L104-L110
This can also technically cause data races.
Workaround
Specify a different client for each
Protocol
usingWithClient
: