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
This commit is contained in:
parent
49ebadd104
commit
c7e9b68f84
|
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ type ZipkinReceiver struct {
|
|||
|
||||
startOnce sync.Once
|
||||
stopOnce sync.Once
|
||||
shutdownWG sync.WaitGroup
|
||||
server *http.Server
|
||||
config *Config
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ func TestDefaultReceivers(t *testing.T) {
|
|||
},
|
||||
{
|
||||
receiver: "zipkin",
|
||||
skipLifecyle: true, // TODO: Upcoming PR to fix zipkin lifecycle.
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue