From c7e9b68f84bbe5ed9082f8d62c4b54c56dc3397a Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Mon, 22 Mar 2021 18:11:18 -0700 Subject: [PATCH] Ensure Zipkin shutdown correctness (#2765) * Fix Zipkin shutdown * Fix zipkin shutdown * Remove nil check for http Serve on OC and OTLP * Switch from channel to WaitGroup for Zipkin shutdown --- receiver/opencensusreceiver/opencensus.go | 2 +- receiver/otlpreceiver/otlp.go | 2 +- receiver/zipkinreceiver/trace_receiver.go | 19 +++++++++++-------- .../default_receivers_test.go | 3 +-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/receiver/opencensusreceiver/opencensus.go b/receiver/opencensusreceiver/opencensus.go index 6535d91e5d7..09b3f146480 100644 --- a/receiver/opencensusreceiver/opencensus.go +++ b/receiver/opencensusreceiver/opencensus.go @@ -261,7 +261,7 @@ func (ocr *ocReceiver) startServer(host component.Host) error { } }() go func() { - if errHTTP := ocr.httpServer().Serve(httpL); errHTTP != nil { + if errHTTP := ocr.httpServer().Serve(httpL); errHTTP != http.ErrServerClosed { host.ReportFatalError(errHTTP) } }() diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index e88fda13cf2..2057abdca44 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -119,7 +119,7 @@ func (r *otlpReceiver) startHTTPServer(cfg *confighttp.HTTPServerSettings, host go func() { defer r.shutdownWG.Done() - if errHTTP := r.serverHTTP.Serve(hln); errHTTP != nil && errHTTP != http.ErrServerClosed { + if errHTTP := r.serverHTTP.Serve(hln); errHTTP != http.ErrServerClosed { host.ReportFatalError(errHTTP) } }() diff --git a/receiver/zipkinreceiver/trace_receiver.go b/receiver/zipkinreceiver/trace_receiver.go index 796a76467fe..94768b9ff2e 100644 --- a/receiver/zipkinreceiver/trace_receiver.go +++ b/receiver/zipkinreceiver/trace_receiver.go @@ -59,10 +59,11 @@ type ZipkinReceiver struct { nextConsumer consumer.TracesConsumer instanceName string - startOnce sync.Once - stopOnce sync.Once - server *http.Server - config *Config + startOnce sync.Once + stopOnce sync.Once + shutdownWG sync.WaitGroup + server *http.Server + config *Config } var _ http.Handler = (*ZipkinReceiver)(nil) @@ -99,13 +100,14 @@ func (zr *ZipkinReceiver) Start(ctx context.Context, host component.Host) error var listener net.Listener listener, err = zr.config.HTTPServerSettings.ToListener() if err != nil { - host.ReportFatalError(err) return } + zr.shutdownWG.Add(1) go func() { - err = zr.server.Serve(listener) - if err != nil { - host.ReportFatalError(err) + defer zr.shutdownWG.Done() + + if errHTTP := zr.server.Serve(listener); errHTTP != http.ErrServerClosed { + host.ReportFatalError(errHTTP) } }() }) @@ -165,6 +167,7 @@ func (zr *ZipkinReceiver) Shutdown(context.Context) error { var err = componenterror.ErrAlreadyStopped zr.stopOnce.Do(func() { err = zr.server.Close() + zr.shutdownWG.Wait() }) return err } diff --git a/service/defaultcomponents/default_receivers_test.go b/service/defaultcomponents/default_receivers_test.go index b1001c7b782..95b37db3f04 100644 --- a/service/defaultcomponents/default_receivers_test.go +++ b/service/defaultcomponents/default_receivers_test.go @@ -75,8 +75,7 @@ func TestDefaultReceivers(t *testing.T) { }, }, { - receiver: "zipkin", - skipLifecyle: true, // TODO: Upcoming PR to fix zipkin lifecycle. + receiver: "zipkin", }, }