Skip to content

Commit

Permalink
fix terminate support cmd (#14079)
Browse files Browse the repository at this point in the history
Fixed stuck on "ctrl+c" for support command
  • Loading branch information
dvovk authored Mar 7, 2025
1 parent 17ca154 commit 891d503
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions turbo/app/support_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,31 @@ func ConnectDiagnostics(cliCtx *cli.Context, logger log.Logger) error {
//
// Listen for incoming requests from diagnostics system and send them to the incommitg request channel
func tunnel(ctx context.Context, cancel context.CancelFunc, sigs chan os.Signal, diagnosticsUrl string, sessionIds []string, debugURLs []string, logger log.Logger) error {
ctx1, cancel1 := context.WithCancel(ctx)
defer cancel1()

go func() {
select {
case <-sigs:
logger.Info("Got interrupt, shutting down...")
cancel1()
case <-ctx1.Done():
logger.Info("Context done")
cancel() // Cancel the outer context
case <-ctx.Done():
return
}
}()

codec, err := createCodec(ctx1, diagnosticsUrl)
codec, err := createCodec(ctx, diagnosticsUrl)
if err != nil {
return err
}
defer codec.Close()

go func() {
<-ctx.Done()
codec.Close()
}()

metricsClient := &http.Client{}
defer metricsClient.CloseIdleConnections()

connections, err := createConnections(ctx1, codec, metricsClient, debugURLs)
connections, err := createConnections(ctx, codec, metricsClient, debugURLs)
if err != nil {
return err
}
Expand All @@ -213,7 +214,7 @@ func tunnel(ctx context.Context, cancel context.CancelFunc, sigs chan os.Signal,
return nil
}

err = sendNodesInfoToDiagnostics(ctx1, codec, sessionIds, connections)
err = sendNodesInfoToDiagnostics(ctx, codec, sessionIds, connections)
if err != nil {
return err
}
Expand All @@ -223,7 +224,7 @@ func tunnel(ctx context.Context, cancel context.CancelFunc, sigs chan os.Signal,
for {
requests, _, err := codec.ReadBatch()
select {
case <-ctx1.Done():
case <-ctx.Done():
return nil
default:
if err != nil {
Expand Down

0 comments on commit 891d503

Please sign in to comment.