Skip to content

Commit

Permalink
Ensure Zipkin shutdown correctness (#2765)
Browse files Browse the repository at this point in the history
* Fix Zipkin shutdown

* Fix zipkin shutdown

* Remove nil check for http Serve on OC and OTLP

* Switch from channel to WaitGroup for Zipkin shutdown
  • Loading branch information
pjanotti authored Mar 23, 2021
1 parent 49ebadd commit c7e9b68
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion receiver/opencensusreceiver/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down
19 changes: 11 additions & 8 deletions receiver/zipkinreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}()
})
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions service/defaultcomponents/default_receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestDefaultReceivers(t *testing.T) {
},
},
{
receiver: "zipkin",
skipLifecyle: true, // TODO: Upcoming PR to fix zipkin lifecycle.
receiver: "zipkin",
},
}

Expand Down

0 comments on commit c7e9b68

Please sign in to comment.