Skip to content

Conversation

ashwat287
Copy link
Contributor

fixes #3875

@ashwat287 ashwat287 force-pushed the RefactorContextBG branch 3 times, most recently from d321bbf to 1566004 Compare August 21, 2025 17:59
@@ -71,7 +71,7 @@ func cloneAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
yBytes, err := yqutil.EvaluateExpression(yq, yContent)
yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yBytes, err := yqutil.EvaluateExpression(cmd.Context(), yq, yContent)
yBytes, err := yqutil.EvaluateExpression(ctx, yq, yContent)

Same for other occurrences of cmd.Context() too

jandubois
jandubois previously approved these changes Aug 23, 2025
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

I have only 2 stylistic nit-picks that you can address, if you want. But we already have existing functions that use _ for the single unnamed parameter, so it isn't a new issue.

There is of course the issue of failing CI, but I think this might be GitHub flakiness; we'll see...

@@ -63,7 +63,7 @@ type Registration interface {
// GuestAgent defines operations for the guest agent.
type GuestAgent interface {
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
ForwardGuestAgent() bool
ForwardGuestAgent(_ context.Context) bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a function/method has only unnamed parameters, then you don't need to specify the _ name. It is only needed when you want to provide a name for parameters with a basic type like bool. int, or string, which are not self-explanatory because you cannot mix named and unnamed parameters.

Suggested change
ForwardGuestAgent(_ context.Context) bool
ForwardGuestAgent(context.Context) bool

Copy link
Contributor Author

@ashwat287 ashwat287 Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we raise a new Issue/PR focusing on removing _ for single unnamed parameter to make it consistent?

@@ -585,19 +585,20 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
remoteUnix := "/run/lima-guestagent.sock"

a.onClose = append(a.onClose, func() error {
ctxBG := context.Background()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a premature optimization. You introduce an extra variable name that the user needs to keep track of instead of calling a very cheap function multiple times.

It doesn't matter much, but I would always try to minimize the context that the developer needs to carry in their head while reading the code, especially if it is a rather long function.

Copy link
Contributor Author

@ashwat287 ashwat287 Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense—I'll drop ctxBG and just call context.Background() directly.

@unsuman
Copy link
Contributor

unsuman commented Sep 12, 2025

@ashwat287, please fix the merge conflicts

@ashwat287 ashwat287 force-pushed the RefactorContextBG branch 5 times, most recently from b9c9050 to fffdae1 Compare September 12, 2025 08:03
Copy link
Contributor

@unsuman unsuman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the pkg/hostagent/dns/dns.go might be the reason for CI failures

Comment on lines 56 to 64
type DNSHandler interface {
ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}

type DNSServer struct {
Server dns.Server
DNSHandler DNSHandler
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? This seems out of context for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce context.Background()
4 participants