Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,17 @@ func server(ctx context.Context, stdout, stderr io.Writer, cfgPath string, hook
// Exit if the config loader fails to start the runners.
// Continuing with failed runners would cause EG to function incorrectly.
case err := <-l.Errors():
cfg.Logger.Error(err, "failed to start runners")
// Read the logger through the loader so the read is guarded by the
// same mutex the reload path holds while replacing it. Reading
// cfg.Logger directly here races with that swap.
l.Logger().Error(err, "failed to start runners")
// Wait for runners to finish before shutting down.
// This is to make sure no orphaned runner process is left running in standalone mode.
l.Wait()
return err
// Wait for the context to be done, which usually happens the process receives a SIGTERM or SIGINT.
case <-ctx.Done():
cfg.Logger.Info("shutting down")
l.Logger().Info("shutting down")
// Wait for runners to finish before shutting down.
// This is to make sure no orphaned runner process is left running in standalone mode.
l.Wait()
Expand Down
8 changes: 8 additions & 0 deletions internal/envoygateway/config/loader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ func (r *Loader) Errors() <-chan error {
return r.hookErr
}

// Logger returns the current logger, safe to call concurrently with a config
// reload replacing it.
func (r *Loader) Logger() logging.Logger {
r.cfgMu.RLock()
defer r.cfgMu.RUnlock()
return r.cfg.Logger
}

// Wait returns when success to acquire mutex, which means no hook is running.
func (r *Loader) Wait() {
r.hookMutex.Lock()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a data race between config-reload and the standalone server's shutdown/error logging by reading the logger through a new mutex-guarded `Loader.Logger()` accessor instead of the shared `cfg.Logger` field directly.