Skip to content

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

@richardpark-msft

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'

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