diff --git a/.chloggen/fixchannel.yaml b/.chloggen/fixchannel.yaml new file mode 100755 index 000000000000..02bdff86ef04 --- /dev/null +++ b/.chloggen/fixchannel.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Stop notification for signals before, increase channel size. + +# One or more tracking issues or pull requests related to the change +issues: [6522] diff --git a/service/collector.go b/service/collector.go index d768f15a1ecb..f7219e7bf4f4 100644 --- a/service/collector.go +++ b/service/collector.go @@ -99,7 +99,7 @@ func New(set CollectorSettings) (*Collector, error) { set: set, state: atomic.NewInt32(int32(Starting)), shutdownChan: make(chan struct{}), - signalsChannel: make(chan os.Signal, 1), + signalsChannel: make(chan os.Signal, 3), asyncErrorChannel: make(chan error), }, nil } @@ -183,6 +183,7 @@ func (col *Collector) Run(ctx context.Context) error { // Always notify with SIGHUP for configuration reloading. signal.Notify(col.signalsChannel, syscall.SIGHUP) + defer signal.Stop(col.signalsChannel) // Only notify with SIGTERM and SIGINT if graceful shutdown is enabled. if !col.set.DisableGracefulShutdown { @@ -197,7 +198,6 @@ LOOP: col.service.telemetrySettings.Logger.Error("Config watch failed", zap.Error(err)) break LOOP } - if err = col.reloadConfiguration(ctx); err != nil { return err } @@ -206,20 +206,17 @@ LOOP: break LOOP case s := <-col.signalsChannel: col.service.telemetrySettings.Logger.Info("Received signal from OS", zap.String("signal", s.String())) - switch s { - case syscall.SIGHUP: - if err := col.reloadConfiguration(ctx); err != nil { - return err - } - default: + if s != syscall.SIGHUP { break LOOP } + if err := col.reloadConfiguration(ctx); err != nil { + return err + } case <-col.shutdownChan: col.service.telemetrySettings.Logger.Info("Received shutdown request") break LOOP case <-ctx.Done(): col.service.telemetrySettings.Logger.Info("Context done, terminating process", zap.Error(ctx.Err())) - // Call shutdown with background context as the passed in context has been canceled return col.shutdown(context.Background()) }