-
Notifications
You must be signed in to change notification settings - Fork 257
Closed
Labels
automatedIssues created by cagentIssues created by cagentkind/bugSomething isn't workingSomething isn't working
Description
🟠 high - bug
File: cmd/root/root.go (line 104)
Code
if isCliPLugin() {
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
originalPreRun := rootCmd.PersistentPreRunE
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
return err
}
if originalPreRun != nil {
if err := originalPreRun(cmd, args); err != nil {
return processErr(ctx, err, stderr, rootCmd)
}
}
return nil
}
rootCmd.SetContext(ctx)
return rootCmd
}, metadata.Metadata{
SchemaVersion: "0.1.0",
Vendor: "Docker Inc.",
Version: version.Version,
})
} else if err := rootCmd.ExecuteContext(ctx); err != nil {
return processErr(ctx, err, stderr, rootCmd)
}Problem
The main function in main.go calls cancel() when root.Execute returns an error or finishes successfully. However, when isCliPLugin() is true, plugin.Run is called, which then sets the context for rootCmd but doesn't handle the cancel() function explicitly after plugin.Run finishes. This could lead to a context not being cancelled, potentially causing goroutine leaks if any goroutines are listening to ctx.Done() and expect it to be closed.
Suggested Fix
The cancel() function should be called after plugin.Run completes, similar to how it's handled in the else if block for rootCmd.ExecuteContext(ctx).
Found by nightly codebase scan
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
automatedIssues created by cagentIssues created by cagentkind/bugSomething isn't workingSomething isn't working