-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
envoy: exit if envoy exits #2240
Conversation
Code Climate has analyzed commit 53c22e8 and detected 0 issues on this pull request. View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm;
I'd remove monitorProcessCancel
from Server
but it's a style preference.
} else { | ||
args = append(args, "--use-dynamic-base-id", "--base-id-path", baseIDPath) | ||
} | ||
srv.restartEpoch++ | ||
|
||
cmd := exec.Command(srv.envoyPath, args...) // #nosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> exec.CommandContext
for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the background context. The context passed to run comes from the on change handler. But envoy needs to survive past the end of this function.
@@ -213,6 +218,13 @@ func (srv *Server) run(ctx context.Context) error { | |||
if err != nil { | |||
return fmt.Errorf("error starting envoy: %w", err) | |||
} | |||
// call Wait to avoid zombie processes | |||
go func() { _ = cmd.Wait() }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why monitorProcessCancel
has to be inside Server
- you can just wait for the process completion in this goroutine, and invoke monitorProcessCancel
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we update envoy config we start a new envoy process using hot-reload. Once hot-reload completes it will kill the previous envoy process. If we don't cancel the previous process monitor, we will immediately exit when this happens.
We have to cancel the process monitor before the process exits.
Summary
If envoy exits unexpectedly, we should use
log.Fatal
to exit as well. This PR also fixes a bug with hot-restart. Therestart-epoch
was supposed to start at 1 for the first restart, not 0.Related issues
Fixes https://github.com/pomerium/internal/issues/414
Checklist
improvement
/bug
/ etc)