Skip to content
Merged
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
20 changes: 14 additions & 6 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
return err
}

runnersDone := make(chan struct{})

Check warning on line 65 in internal/cmd/server.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/server.go#L65

Added line #L65 was not covered by tests
hook := func(c context.Context, cfg *config.Server) error {
cfg.Logger.Info("Setup runners")
if err := setupRunners(c, cfg); err != nil {
cfg.Logger.Error(err, "failed to setup runners")
cfg.Logger.Info("Start runners")
if err := startRunners(c, cfg); err != nil {
cfg.Logger.Error(err, "failed to start runners")

Check warning on line 69 in internal/cmd/server.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/server.go#L67-L69

Added lines #L67 - L69 were not covered by tests
return err
}
runnersDone <- struct{}{}

Check warning on line 72 in internal/cmd/server.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/server.go#L72

Added line #L72 was not covered by tests
return nil
}
l := loader.New(cfgPath, cfg, hook)
Expand All @@ -84,11 +86,14 @@
return err
}

// Wait exit signal
// Wait for the context to be done, which usually happens the process receives a SIGTERM or SIGINT.
<-ctx.Done()
Copy link
Copy Markdown
Member Author

@mathetake mathetake Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note on why <-runnersDone is needed; Right after ctx is canceled, this main goroutine will call os.Exit(0) vs runners are not running on the main goroutine. so without blocking and waiting for it to return, this will highly likely leave some undesirable state orphaned that is supposed to be cleaned up by non-main goroutine where runners' Close() is executed.


cfg.Logger.Info("shutting down")

// Wait for runners to finish.
<-runnersDone

Check warning on line 96 in internal/cmd/server.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/server.go#L94-L96

Added lines #L94 - L96 were not covered by tests
return nil
}

Expand Down Expand Up @@ -132,9 +137,12 @@
return cfg, nil
}

// setupRunners starts all the runners required for the Envoy Gateway to
// startRunners starts all the runners required for the Envoy Gateway to
// fulfill its tasks.
func setupRunners(ctx context.Context, cfg *config.Server) (err error) {
//
// This will block until the context is done, and returns after synchronously
// closing all the runners.
func startRunners(ctx context.Context, cfg *config.Server) (err error) {

Check warning on line 145 in internal/cmd/server.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/server.go#L145

Added line #L145 was not covered by tests
channels := struct {
pResources *message.ProviderResources
xdsIR *message.XdsIR
Expand Down