Skip to content
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

roundup of cleanup fixes #144

Merged
merged 4 commits into from
Feb 19, 2019
Merged

roundup of cleanup fixes #144

merged 4 commits into from
Feb 19, 2019

Conversation

Stebalien
Copy link
Member

This PR includes fixes/cleanups for a bunch of issues I noticed while debugging #143.

Checkout the commit messages for details. The important fix is waiting for the Executor to finish. before returning from Run. Not doing this was causing us to close the process before Run was actually finished.

@Stebalien Stebalien requested a review from keks as a code owner February 19, 2019 10:27
@ghost ghost assigned Stebalien Feb 19, 2019
@ghost ghost added the status/in-progress In progress label Feb 19, 2019
}()
}
} else {
// not using this channel today
close(errCh)
}

defer func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

We really shouldn't be catching panics this way. This only catches panics where the panic value is an error so it's kind of arbitrary anyways.

IIRC, this was added because we had a bunch of races around Close and SetError but those have since been fixed.

@@ -184,16 +184,14 @@ var RootCmd = &cmds.Command{
PostRun: cmds.PostRunMap{
cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error {
clire := re.(cli.ResponseEmitter)

defer re.Close()
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't need to do this explicitly anymore. It's up to the executor to close the response emitter.

return re.CloseWithError(nil)
}

func (re *responseEmitter) CloseWithError(err error) error {
Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, it's easier to read this when all the close logic is in the same function.

@Stebalien
Copy link
Member Author

Also fixes #113.

Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

I'm not fully familiar with this code, but this LGTM

* Don't catch panics. We mostly had this to catch issues with the _commands_
  library but catching random panics is really not the best idea. Worse, this
  code was rather arbitrary and only caught panics implementing `error`.

* Make sure to wait for the PostRun to finish before returning.
It wasn't a reliable way to determine if the command was "done". We need to wait
for run, post-run, etc. to finish first.

* Fixes #143

This commit:

1. Removes the exit channel from the CLI response emitter.
2. Adds a `Status()` function to the `cli.ResponseEmitter` as a replacement
   for (1).
3. Renames `Exit(code)` to `SetStatus(code)`. This new function doesn't
   immediately _do_ anything other than set the status.
4. Make sure to wait for _everything_ to finish before returning from `cli.Run`.
We inserted these while transitioning to the new API but we've never hit one.
@Stebalien Stebalien merged commit ff61303 into master Feb 19, 2019
@Stebalien Stebalien deleted the fix/stuff branch February 19, 2019 20:50
@ghost ghost removed the status/in-progress In progress label Feb 19, 2019
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.

2 participants