cardano-community / koios-go-client

Go Client library for Koios API
https://pkg.go.dev/github.com/cardano-community/koios-go-client/v3
Apache License 2.0
10 stars 4 forks source link

requestWithStats will have data race in some edge cases #15

Open mkungla opened 2 years ago

mkungla commented 2 years ago

Describe the bug

Some edge cases when request context is canceled while request with httptrace.WithClientTrace is busy can cause data race,

https://github.com/cardano-community/koios-go-client/blob/2c4a0061bb604cab2e401129861df57d1e4a0b85/client.go#L195

https://pkg.go.dev/net/http/httptrace#ContextClientTrace

ClientTrace is a set of hooks to run at various stages of an outgoing HTTP request. Any particular hook may be nil. Functions may be called concurrently from different goroutines and some may be called after the request has completed or failed.

To Reproduce Steps to reproduce the behavior:

  1. When context is canceled nanoseconds after rate limiter allows next request