Skip to content

Commit

Permalink
Remove goroutine spawning in favor of the asyn nature of UDP (#794)
Browse files Browse the repository at this point in the history
Follow up from feedback in #566
  • Loading branch information
sonofachamp authored Aug 25, 2020
1 parent 8217929 commit 339355d
Showing 1 changed file with 2 additions and 11 deletions.
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

0 comments on commit 339355d

Please sign in to comment.