Skip to content

Commit

Permalink
Init limits if nil (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice authored Jul 19, 2024
1 parent ec57183 commit 9720871
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ func NewHTTPTransport() *HTTPTransport {
transport := HTTPTransport{
BufferSize: defaultBufferSize,
Timeout: defaultTimeout,
limits: make(ratelimit.Map),
}
return &transport
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9720871

Please sign in to comment.