New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plumb context.Context
down into functions that use util/cmd
functions
#6468
Plumb context.Context
down into functions that use util/cmd
functions
#6468
Conversation
Codecov Report
@@ Coverage Diff @@
## main #6468 +/- ##
==========================================
- Coverage 70.29% 70.26% -0.04%
==========================================
Files 510 510
Lines 22982 22985 +3
==========================================
- Hits 16156 16151 -5
- Misses 5770 5776 +6
- Partials 1056 1058 +2
Continue to review full report at Codecov.
|
@@ -73,7 +74,7 @@ func (g *git) diffWithBaseline(path string) ([]byte, error) { | |||
|
|||
func (g *git) run(args ...string) ([]byte, error) { | |||
cmd := exec.Command(g.path, args...) | |||
out, err := util.RunCmdOut(cmd) | |||
out, err := util.RunCmdOut(context.Background(), cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another PR to move replace context.Background to context.TODO.
Do you want to sync with that and see why TODO
is preferred?
From docs, looks like Background context is never cancelled.
https://pkg.go.dev/context#Background
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that context.TODO
is a hint to the dev that if ever a proper context becomes available in future by a change in the function parameters or something, then plumb that through. Whereas context.Background
is a deliberate use even if a parent context is available. That's what I understood from @ahmetb's PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's the case. ideally a context.Background() is for a call stack that can be cancelled from a central place, e.g. Ctrl-C. Background threads with separate lifecycle (as the name also says) get a new Background context.
If you don't plumb yet but intend do plumb someday, you can use context.TODO, which is identical to Background() functionally, only different in semantics and indicates your intention.
Code changes Look good. |
After applying a diff and some validation I can now see debug logs in relevant nodes. Diff i applied:
|
Please apply the diff to make sure the context values are plumbed through
Follow up cleaning tasks
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for Monday in advance.
can this be merged @MarlonGamez ? |
Related: #5368
Description
This PR plumbs
context.Context
parameter into functions in order to have acontext.Context
variable inutil.RunCmd
and related functions