Skip to content

Commit 7efac33

Browse files
Remove Shutdown Hooks and Dump Admin State on Startup (#474)
Signed-off-by: Adrian Cole <[email protected]> Co-authored-by: Adrian Cole <[email protected]>
1 parent 4bd4dda commit 7efac33

39 files changed

+1104
-1021
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ build/format: go.mod $(all_sources)
173173
@$(go) mod tidy
174174
@$(go) run $(nwa) add --mute -t .licenseheader -T raw "**/*.go"
175175
@$(go) run $(gofumpt) -l -w .
176-
# gofumpt organizes imports, but does not handle local grouping.
176+
@# gofumpt organizes imports, but does not handle local grouping.
177177
@$(go) run $(gosimports) -local github.com/tetratelabs/ -w $(shell find . -name '*.go' -type f)
178178
@mkdir -p $(@D) && touch $@
179179

USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ To run Envoy, execute `func-e run -c your_envoy_config.yaml`. This
33
downloads and installs the latest version of Envoy for you.
44

55
To list versions of Envoy you can use, execute `func-e versions -a`. To
6-
choose one, invoke `func-e use 1.34.2`. This installs into
7-
`$FUNC_E_HOME/versions/1.34.2`, if not already present. You may also use
6+
choose one, invoke `func-e use 1.34.3`. This installs into
7+
`$FUNC_E_HOME/versions/1.34.3`, if not already present. You may also use
88
minor version, such as `func-e use 1.34`.
99

1010
You may want to override `$ENVOY_VERSIONS_URL` to supply custom builds or

api/func-e.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ type runOpts struct {
9090
// Run downloads Envoy and runs it as a process with the arguments
9191
// passed to it. Use RunOption for configuration options.
9292
//
93-
// This blocks until the context is done or the process exits. The error might be
94-
// context.Canceled if the context is done or an error from the process.
93+
// On success, this blocks and returns nil when either `ctx` is done, or the
94+
// process exits with status zero.
9595
func Run(ctx context.Context, args []string, options ...RunOption) error {
9696
// TODO: we need a real API and it being an interface in this package, initialized in the root
9797
// directory like wazero does. That this stitches the impl makes it not an API package and causes

api/func-e_run_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Tetrate
1+
// Copyright func-e contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
package api
@@ -14,8 +14,8 @@ func TestRun(t *testing.T) {
1414
e2e.TestRun(context.Background(), t, fakeFuncEFactory{})
1515
}
1616

17-
func TestRun_MinimalListener(t *testing.T) {
18-
e2e.TestRun_MinimalListener(context.Background(), t, fakeFuncEFactory{})
17+
func TestRun_RunDirectory(t *testing.T) {
18+
e2e.TestRun_RunDirectory(context.Background(), t, fakeFuncEFactory{})
1919
}
2020

2121
func TestRun_InvalidConfig(t *testing.T) {
@@ -25,3 +25,8 @@ func TestRun_InvalidConfig(t *testing.T) {
2525
func TestRun_StaticFile(t *testing.T) {
2626
e2e.TestRun_StaticFile(context.Background(), t, fakeFuncEFactory{})
2727
}
28+
29+
func TestRun_CtrlCs(t *testing.T) {
30+
// This doesn't call ctrl-c, rather cancels the context multiple times
31+
e2e.TestRun_CtrlCs(context.Background(), t, fakeFuncEFactory{})
32+
}

api/func-e_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Tetrate
1+
// Copyright func-e contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
package api
@@ -48,8 +48,10 @@ type fakeFuncE struct {
4848

4949
// Interrupt cancels the context created in Run as we don't want to actually interrupt the calling test!
5050
func (f *fakeFuncE) Interrupt(context.Context) error {
51-
f.cancelFunc()
52-
f.cancelFunc = nil
51+
if f.cancelFunc != nil {
52+
f.cancelFunc()
53+
// Don't set to nil in case interrupt is called multiple times (ctrl+c twice)
54+
}
5355
return nil
5456
}
5557

e2e/func-e_run_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Tetrate
1+
// Copyright func-e contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
package e2e
@@ -14,8 +14,8 @@ func TestRun(t *testing.T) {
1414
e2e.TestRun(context.Background(), t, funcEFactory{})
1515
}
1616

17-
func TestRun_MinimalListener(t *testing.T) {
18-
e2e.TestRun_MinimalListener(context.Background(), t, funcEFactory{})
17+
func TestRun_RunDirectory(t *testing.T) {
18+
e2e.TestRun_RunDirectory(context.Background(), t, funcEFactory{})
1919
}
2020

2121
func TestRun_InvalidConfig(t *testing.T) {
@@ -25,3 +25,7 @@ func TestRun_InvalidConfig(t *testing.T) {
2525
func TestRun_StaticFile(t *testing.T) {
2626
e2e.TestRun_StaticFile(context.Background(), t, funcEFactory{})
2727
}
28+
29+
func TestRun_CtrlCs(t *testing.T) {
30+
e2e.TestRun_CtrlCs(context.Background(), t, funcEFactory{})
31+
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/stretchr/testify v1.10.0
88
github.com/ulikunitz/xz v0.5.12
99
github.com/urfave/cli/v2 v2.27.7
10-
golang.org/x/sync v0.16.0
1110
gopkg.in/yaml.v3 v3.0.1
1211
)
1312

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAz
4545
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
4646
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
4747
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
48-
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
49-
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
5048
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5149
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5250
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/api/run.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/tetratelabs/func-e/internal/envoy"
16-
"github.com/tetratelabs/func-e/internal/envoy/shutdown"
1716
"github.com/tetratelabs/func-e/internal/globals"
1817
"github.com/tetratelabs/func-e/internal/version"
1918
)
@@ -53,7 +52,9 @@ func EnsurePatchVersion(ctx context.Context, o *globals.GlobalOpts, v version.Ve
5352
return vv, nil
5453
}
5554

56-
// Run runs Envoy with the given arguments
55+
// Run runs Envoy with the given arguments.
56+
// Returns nil when Envoy exits cleanly, including when interrupted by signals (SIGINT/SIGTERM).
57+
// This matches Envoy's behavior of returning exit code 0 on graceful shutdown.
5758
func Run(ctx context.Context, o *globals.GlobalOpts, args []string) error {
5859
if err := initializeRunOpts(ctx, o); err != nil {
5960
return err
@@ -77,11 +78,6 @@ func Run(ctx context.Context, o *globals.GlobalOpts, args []string) error {
7778
r.ErrFile = stderrLog
7879
r.Err = io.MultiWriter(o.EnvoyErr, stderrLog)
7980

80-
for _, hook := range shutdown.DefaultShutdownHooks {
81-
if err := hook(r); err != nil {
82-
fmt.Fprintf(r.Out, "failed to enable shutdown hook: %s\n", err) //nolint:errcheck
83-
}
84-
}
8581
return r.Run(ctx, args)
8682
}
8783

internal/cmd/run.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ Envoy interprets the '[arguments...]' and runs in the current working
3131
directory (aka $PWD) until func-e is interrupted (ex Ctrl+C, Ctrl+Break).
3232
3333
Envoy's process ID and console output write to "envoy.pid", stdout.log" and
34-
"stderr.log" in the run directory (` + fmt.Sprintf("`%s`", runDirectoryExpression) + `).
35-
When interrupted, shutdown hooks write files including network and process
36-
state. On exit, these archive into ` + fmt.Sprintf("`%s.tar.gz`", runDirectoryExpression),
34+
"stderr.log" in the run directory (` + fmt.Sprintf("`%s`", runDirectoryExpression) + `).`,
3735
Before: func(c *cli.Context) error {
3836
if err := api.EnsureEnvoyVersion(c.Context, o); err != nil {
3937
return NewValidationError(err.Error())

0 commit comments

Comments
 (0)