Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init limits if nil #844

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@
transport := HTTPTransport{
BufferSize: defaultBufferSize,
Timeout: defaultTimeout,
limits: make(ratelimit.Map),
}
return &transport
}
Expand Down Expand Up @@ -550,9 +549,14 @@
}
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 @@
}

t.mu.Lock()
if t.limits == nil {
t.limits = make(ratelimit.Map)

Check warning on line 698 in transport.go

View check run for this annotation

Codecov / codecov/patch

transport.go#L698

Added line #L698 was not covered by tests
}

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
Loading