Skip to content

(Go SDK) Cancelling a context, passed to client.Start, kills the copilot CLI process #668

Closed

Description

@richardpark-msft

copilot.Client.Start, under the covers, is using exec.CommandContext for the background copilot CLI process.

exec.CommandContext has a little bit of a footgun, where if you cancel the context that was passed to it, it kills the underlying process. This works great for most command usages, but in this case, where you specifically have a CLI process that intends to outlive 'Start', it results in this idiomatic code causing issues:

client := copilot.NewClient()

ctx, cancel := context.WithCancel(context.Background())
client.Start(ctx)  
cancel()     // <- when this cancels it'll kill copilot CLI

sess, err := client.CreateSession()
// err ==  'CLI process exited: signal: killed'

Activity

  1. changed the title [-]Cancelling a context, passed to client.Start, kills the `copilot` CLI process[/-] [+](Go SDK) Cancelling a context, passed to client.Start, kills the `copilot` CLI process[/+] on Mar 4, 2026
  2. qmuntal commented on Mar 5, 2026

    @qmuntal
    Contributor

    Thanks for reporting this issue. Agree that the CLI lifespan shouldn't be tied to the context passed to Client.Start. I've checked the .NET SDK, which also supports cancellation tokens, and confirmed that canceling the token doesn't kill the CLI.

    Will submit a fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions