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

routing/http: fix goroutine/memory leak [skip changelog] #618

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
19 changes: 13 additions & 6 deletions routing/http/contentrouter/contentrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

// readProviderResponses reads peer records (and bitswap records for legacy
// compatibility) from the iterator into the given channel.
func readProviderResponses(iter iter.ResultIter[types.Record], ch chan<- peer.AddrInfo) {
func readProviderResponses(ctx context.Context, iter iter.ResultIter[types.Record], ch chan<- peer.AddrInfo) {
defer close(ch)
defer iter.Close()
for iter.Next() {
Expand All @@ -140,10 +140,14 @@
addrs = append(addrs, a.Multiaddr)
}

ch <- peer.AddrInfo{
select {
case <-ctx.Done():
return

Check warning on line 145 in routing/http/contentrouter/contentrouter.go

View check run for this annotation

Codecov / codecov/patch

routing/http/contentrouter/contentrouter.go#L144-L145

Added lines #L144 - L145 were not covered by tests
case ch <- peer.AddrInfo{
ID: *result.ID,
Addrs: addrs,
Addrs: addrs}:
}

//lint:ignore SA1019 // ignore staticcheck
case types.SchemaBitswap:
//lint:ignore SA1019 // ignore staticcheck
Expand All @@ -162,9 +166,12 @@
addrs = append(addrs, a.Multiaddr)
}

ch <- peer.AddrInfo{
select {
case <-ctx.Done():
return

Check warning on line 171 in routing/http/contentrouter/contentrouter.go

View check run for this annotation

Codecov / codecov/patch

routing/http/contentrouter/contentrouter.go#L170-L171

Added lines #L170 - L171 were not covered by tests
case ch <- peer.AddrInfo{
ID: *result.ID,
Addrs: addrs,
Addrs: addrs}:
}
}
}
Expand All @@ -179,7 +186,7 @@
return ch
}
ch := make(chan peer.AddrInfo)
go readProviderResponses(resultsIter, ch)
go readProviderResponses(ctx, resultsIter, ch)
return ch
}

Expand Down
Loading