From 7f1fc77731ce4059d3e7a490453c1036c2ef3135 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 9 Mar 2022 15:15:52 -0600 Subject: [PATCH] Use CLI context when running tunnel When embedding the tunnel command inside another CLI, it became difficult to test shutdown behavior due to this leaking tunnel. By using the command context, we're able to shutdown gracefully. --- cmd/cloudflared/tunnel/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cloudflared/tunnel/cmd.go b/cmd/cloudflared/tunnel/cmd.go index 43eee046..075ceb3c 100644 --- a/cmd/cloudflared/tunnel/cmd.go +++ b/cmd/cloudflared/tunnel/cmd.go @@ -274,7 +274,7 @@ func StartServer( logClientOptions(c, log) // this context drives the server, when it's cancelled tunnel and all other components (origins, dns, etc...) should stop - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(c.Context) defer cancel() go waitForSignal(graceShutdownC, log)