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

Remove goroutine spawning in favor of the async nature of UDP #794

Merged
merged 1 commit into from
Aug 25, 2020
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
13 changes: 2 additions & 11 deletions receiver/statsdreceiver/transport/udp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"net"
"strings"
"sync"

metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
"go.opentelemetry.io/collector/consumer"
Expand All @@ -31,7 +30,6 @@ import (
)

type udpServer struct {
wg sync.WaitGroup
packetConn net.PacketConn
reporter Reporter
}
Expand Down Expand Up @@ -66,14 +64,9 @@ func (u *udpServer) ListenAndServe(
for {
n, _, err := u.packetConn.ReadFrom(buf)
if n > 0 {
u.wg.Add(1)
bufCopy := make([]byte, n)
copy(bufCopy, buf)
// TODO: remove this goroutine spawning
go func() {
u.handlePacket(parser, nextConsumer, bufCopy)
u.wg.Done()
}()
u.handlePacket(parser, nextConsumer, bufCopy)
}
if err != nil {
u.reporter.OnDebugf("UDP Transport (%s) - ReadFrom error: %v",
Expand All @@ -90,9 +83,7 @@ func (u *udpServer) ListenAndServe(
}

func (u *udpServer) Close() error {
err := u.packetConn.Close()
u.wg.Wait()
return err
return u.packetConn.Close()
}

func (u *udpServer) handlePacket(
Expand Down