TBufferedServer: Avoid channel close/send race on Stop (#2583)
TBufferedServer: Avoid channel close/send race on Stop (#2583)

TBufferedServer.Close() may close the data channel before
Serve detects it. Move chan close() to Serve to prevent
a panic caused by sending on a closed channel.

See also https://github.com/golang/go/issues/27769#issuecomment-423045727

	=== RUN   TestTBufferedServer_SendReceive
	==================
	WARNING: DATA RACE
	Write at 0x00c000074850 by goroutine 9:
	  runtime.closechan()
	      /home/travis/.gimme/versions/go1.15.2.linux.amd64/src/runtime/chan.go:352 +0x0
	  github.com/jaegertracing/jaeger/cmd/agent/app/servers.(*TBufferedServer).Stop()
	...
	Previous read at 0x00c000074850 by goroutine 10:
	  runtime.chansend()
	      /home/travis/.gimme/versions/go1.15.2.linux.amd64/src/runtime/chan.go:158 +0x0
	  github.com/jaegertracing/jaeger/cmd/agent/app/servers.(*TBufferedServer).Serve()
	      /home/travis/gopath/src/github.com/jaegertracing/jaeger/cmd/agent/app/servers/tbuffered_server.go:97 +0x264
	...
	==================
	    testing.go:1042: race detected during execution of test
	--- FAIL: TestTBufferedServer_SendReceive (0.01s)

Closes #2577

Signed-off-by: Carl Henrik Lunde <afbb228c01ef716d910901bf3f59b12538bf9acc@ifi.uio.no>
jpkrohling/jaeger,pavolloffay/jaeger,pavolloffay/jaeger,pavolloffay/jaeger,jaegertracing/jaeger,jpkrohling/jaeger,uber/jaeger,jpkrohling/jaeger,jpkrohling/jaeger,pavolloffay/jaeger,jaegertracing/jaeger,jaegertracing/jaeger,jpkrohling/jaeger,uber/jaeger,uber/jaeger,jaegertracing/jaeger,uber/jaeger,pavolloffay/jaeger,jaegertracing/jaeger