From 1c29d1535cf993a3cbeff56d575f062dfe89063c Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 20 Oct 2017 23:36:14 +0200 Subject: [PATCH] fix data race in tcp server --- testing/servers/tcp/tcp.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/testing/servers/tcp/tcp.go b/testing/servers/tcp/tcp.go index 8117318d..48c819c0 100644 --- a/testing/servers/tcp/tcp.go +++ b/testing/servers/tcp/tcp.go @@ -12,7 +12,6 @@ type Server struct { MsgProcessor func(msg []byte) []byte SendFirst []byte Listen net.Address - accepting bool listener *net.TCPListener } @@ -37,12 +36,11 @@ func (server *Server) Start() (net.Destination, error) { } func (server *Server) acceptConnections(listener *net.TCPListener) { - server.accepting = true - for server.accepting { + for { conn, err := listener.Accept() if err != nil { fmt.Printf("Failed accept TCP connection: %v\n", err) - continue + return } go server.handleConnection(conn) @@ -71,7 +69,6 @@ func (server *Server) handleConnection(conn net.Conn) { conn.Close() } -func (v *Server) Close() { - v.accepting = false - v.listener.Close() +func (server *Server) Close() { + server.listener.Close() }