diff --git a/transport.go b/transport.go index 20f69941f..02fc1d4f1 100644 --- a/transport.go +++ b/transport.go @@ -357,7 +357,6 @@ func NewHTTPTransport() *HTTPTransport { transport := HTTPTransport{ BufferSize: defaultBufferSize, Timeout: defaultTimeout, - limits: make(ratelimit.Map), } return &transport } @@ -550,9 +549,14 @@ func (t *HTTPTransport) worker() { } Logger.Printf("Sending %s failed with the following error: %s", eventType, string(b)) } + t.mu.Lock() + if t.limits == nil { + t.limits = make(ratelimit.Map) + } t.limits.Merge(ratelimit.FromResponse(response)) t.mu.Unlock() + // Drain body up to a limit and close it, allowing the // transport to reuse TCP connections. _, _ = io.CopyN(io.Discard, response.Body, maxDrainResponseBytes) @@ -690,6 +694,10 @@ func (t *HTTPSyncTransport) SendEventWithContext(ctx context.Context, event *Eve } t.mu.Lock() + if t.limits == nil { + t.limits = make(ratelimit.Map) + } + t.limits.Merge(ratelimit.FromResponse(response)) t.mu.Unlock() diff --git a/transport_test.go b/transport_test.go index 9d70db2f7..b371cae45 100644 --- a/transport_test.go +++ b/transport_test.go @@ -434,6 +434,7 @@ func TestHTTPTransport(t *testing.T) { e.EventID = EventID(id) transport.SendEvent(e) + t.Logf("[CLIENT] {%.4s} event sent", e.EventID) return id }