From 61a16538a14417522553e3a81ff56c9e90cebc71 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Thu, 14 Dec 2023 11:33:41 -0500 Subject: [PATCH] Use CLI context when running tunnel (#597) 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 7de76a54..e5b0ebb5 100644 --- a/cmd/cloudflared/tunnel/cmd.go +++ b/cmd/cloudflared/tunnel/cmd.go @@ -340,7 +340,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)