diff --git a/vendor/github.com/k-sone/snmpgo/.gitrepo b/vendor/github.com/k-sone/snmpgo/.gitrepo index c1e8e6d9fd..0e84887177 100644 --- a/vendor/github.com/k-sone/snmpgo/.gitrepo +++ b/vendor/github.com/k-sone/snmpgo/.gitrepo @@ -4,8 +4,8 @@ ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme ; [subrepo] - remote = https://github.com/k-sone/snmpgo.git - branch = master - commit = d227fb7b907b5f3695799a3230971ebd7c414d47 - parent = bf8e5581beb46e1b08625e6380675f2aaddf3967 + remote = https://github.com/influxdata/snmpgo.git + branch = nc-fix-server-race + commit = 41d2f4757c391c2a7fac77d9ad9aafff66c39f18 + parent = 2bf7773eafa4d68b6bd0a348e753e378fe68b384 cmdver = 0.3.0 diff --git a/vendor/github.com/k-sone/snmpgo/server.go b/vendor/github.com/k-sone/snmpgo/server.go index c898fda969..2157c043bc 100644 --- a/vendor/github.com/k-sone/snmpgo/server.go +++ b/vendor/github.com/k-sone/snmpgo/server.go @@ -6,6 +6,7 @@ import ( "math" "net" "runtime" + "sync" "time" ) @@ -159,6 +160,7 @@ type TrapServer struct { mps map[SNMPVersion]messageProcessing secs map[SNMPVersion]*securityMap transport transport + servingMu sync.RWMutex serving bool // Error Logger which will be used for logging of default errors @@ -187,7 +189,9 @@ func (s *TrapServer) Serve(listener TrapListener) error { if listener == nil { return &ArgumentError{Message: "listener is nil"} } + s.servingMu.Lock() s.serving = true + s.servingMu.Unlock() size := s.args.MessageMaxSize if size < recvBufferSize { size = recvBufferSize @@ -195,7 +199,10 @@ func (s *TrapServer) Serve(listener TrapListener) error { for { conn, err := s.transport.Listen() - if !s.serving { + s.servingMu.RLock() + serving := s.serving + s.servingMu.RUnlock() + if !serving { return nil } if err != nil { @@ -211,7 +218,10 @@ func (s *TrapServer) Serve(listener TrapListener) error { for { _, src, msg, err := s.transport.Read(conn, buf) if _, ok := err.(net.Error); ok { - if s.serving { + s.servingMu.RLock() + serving := s.serving + s.servingMu.RUnlock() + if serving { s.logf("trap: failed to read packet: %v", err) } return @@ -225,7 +235,9 @@ func (s *TrapServer) Serve(listener TrapListener) error { // Close shuts down the server. func (s *TrapServer) Close() error { + s.servingMu.Lock() s.serving = false + s.servingMu.Unlock() return s.transport.Close(nil) } diff --git a/vendor/github.com/k-sone/snmpgo/transport.go b/vendor/github.com/k-sone/snmpgo/transport.go index c355db7574..79930022b1 100644 --- a/vendor/github.com/k-sone/snmpgo/transport.go +++ b/vendor/github.com/k-sone/snmpgo/transport.go @@ -23,14 +23,19 @@ type packetTransport struct { } func (t *packetTransport) Listen() (interface{}, error) { - if t.conn != nil { + t.lock.Lock() + c := t.conn + t.lock.Unlock() + if c != nil { <-t.anchor return nil, nil } - var err error - t.conn, err = net.ListenPacket(t.network, t.localAddr) - return t.conn, err + c, err := net.ListenPacket(t.network, t.localAddr) + t.lock.Lock() + t.conn = c + t.lock.Unlock() + return c, err } func (t *packetTransport) Read(conn interface{}, buf []byte) (num int, src net.Addr, msg message, err error) {