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

ensure withTimeout deals nicely with runtime.Goexit() #890

Merged
merged 1 commit into from
Jun 10, 2022

Conversation

rubensayshi
Copy link
Contributor

@rubensayshi rubensayshi commented Jun 7, 2022

We've been running our tests from an OnStart hook, but when one of the tests calls t.FailNow() it will under-the-hood call runtime.Goexit() and then the OnStart hook just sits there waiting for the timeout...

With this change the withTimeout can never get stuck when for some reason runtime.Goexit() got called.

I'm not 100% sure returning the fmt.Errorf("withTimeout exit without returning") is the best choice,
c <- nil could also work, that would make it look like the callback succeeded and continue calling the next OnStart or OnStop hook.

@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch 2 times, most recently from 9d07f7f to dec0ea4 Compare June 7, 2022 15:42
Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

Hey @rubensayshi, thanks for submitting this! Left a suggestion for a fix here.

Re: the error message, I believe withTimeout exit without returning is a little too implementation-detail level error message for most users to comprehend.

Can we instead say something like: OnStart callback __ exited without returning? (and it'd be OnStop callback exited... for onstop callbacks).

I can also make those changes to this PR on your behalf if you want. Let me know

app.go Outdated Show resolved Hide resolved
@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch 3 times, most recently from 14b0570 to e164e5f Compare June 7, 2022 20:02
@rubensayshi
Copy link
Contributor Author

updated to include both your suggestions, I don't think its strictly necessary as there isn't a race in the normal scenario, but with the boolean it might prevent odd future issues and it's more clear what the intention of the code is as well.

I was thinking ... I think the only scenario where this gets triggered is a runtime.Goexit() ... I'm not sure. but maybe the right response would be to runtime.Goexit() in withTimeout as well?
Though returning an error seems cleaner and clearer to the caller.

@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch 2 times, most recently from d2f77ad to 04f31d2 Compare June 8, 2022 14:15
@rubensayshi
Copy link
Contributor Author

updated to make the error get the wrapping with the "... hook added by ...", so an error looks like;

OnStart hook added by package/path.Func failed: exited without returning

@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch from 04f31d2 to a2d8623 Compare June 8, 2022 14:19
Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes. There are linter and test failures that I wanted to address, but because this is a fork that lives in an organization, I couldn't push these changes directly to this PR. If you merge prvbl#1 into this branch that should update this PR.

@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch from 243c2ca to bce7371 Compare June 9, 2022 06:32
@rubensayshi
Copy link
Contributor Author

rubensayshi commented Jun 9, 2022

hey @sywhang thanks for that, you could have also commented and I would have changed, but much appreciated that you submitted the suggested changes ;)

PR updated to include you changes.

@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #890 (5a41d4c) into master (e4e7928) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #890   +/-   ##
=======================================
  Coverage   98.53%   98.53%           
=======================================
  Files          30       30           
  Lines        1157     1163    +6     
=======================================
+ Hits         1140     1146    +6     
  Misses         11       11           
  Partials        6        6           
Impacted Files Coverage Δ
app.go 95.04% <100.00%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e4e7928...5a41d4c. Read the comment docs.

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

Thanks. This looks good to me now. Looks like we aren't able to merge yet because the branch is out of date with the base branch. If you can make the branch up to date with base branch, we'll go ahead and merge this.

@sywhang sywhang enabled auto-merge (squash) June 9, 2022 17:15
@sywhang sywhang disabled auto-merge June 9, 2022 17:16
@rubensayshi rubensayshi force-pushed the with-timeout-failnow branch from bce7371 to 5a41d4c Compare June 10, 2022 07:19
@rubensayshi
Copy link
Contributor Author

rebased, and thanks for helping me polish this <3

@sywhang
Copy link
Contributor

sywhang commented Jun 10, 2022

Great! Merging now. Thanks again for your contribution.

@sywhang sywhang merged commit b74068d into uber-go:master Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants