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 OnStart/OnStop hooks can only be called once #931

Merged
merged 3 commits into from Aug 24, 2022

Conversation

sywhang
Copy link
Contributor

@sywhang sywhang commented Aug 23, 2022

It is possible for a user to erroneously call app.Run() then
follow up by calling app.Stop(). In such a case, it is possible
for the app.Stop() method to be called by two goroutines concurrently,
resulting in a race.

This adds a state in the App to keep track of whether Stop() has been
invoked so that such a race can be prevented.

Fix #930
Internal Ref: GO-1606

It is possible for a user to erroneously call app.Run() then
follow up by calling app.Stop(). In such a case, it is possible
for the app.Stop() method to be called by two goroutines concurrently,
resulting in a race.

This adds a state in the App to keep track of whether Stop() has been
invoked so that such a race can be prevented.

Fix uber-go#930
Internal Ref: GO-1606
@sywhang sywhang requested a review from abhinav August 23, 2022 16:31
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #931 (1ab9c45) into master (b98765e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #931   +/-   ##
=======================================
  Coverage   98.72%   98.72%           
=======================================
  Files          30       30           
  Lines        1332     1337    +5     
=======================================
+ Hits         1315     1320    +5     
  Misses         11       11           
  Partials        6        6           
Impacted Files Coverage Δ
app.go 95.15% <100.00%> (+0.10%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sywhang sywhang changed the title Ensure OnStop hooks can only be called once Ensure OnStart/OnStop hooks can only be called once Aug 23, 2022
app_test.go Outdated Show resolved Hide resolved
app_test.go Outdated Show resolved Hide resolved
Co-authored-by: Abhinav Gupta <mail@abhinavg.net>
@sywhang sywhang merged commit 5566339 into uber-go:master Aug 24, 2022
@sywhang sywhang deleted the 930 branch August 24, 2022 05:20
sywhang added a commit to sywhang/fx that referenced this pull request Sep 28, 2022
sywhang added a commit that referenced this pull request Sep 28, 2022
sywhang added a commit to sywhang/fx that referenced this pull request Sep 28, 2022
sywhang added a commit to sywhang/fx that referenced this pull request Oct 11, 2022
* Ensure OnStop hooks can only be called once

It is possible for a user to erroneously call app.Run() then
follow up by calling app.Stop(). In such a case, it is possible
for the app.Stop() method to be called by two goroutines concurrently,
resulting in a race.

This adds a state in the App to keep track of whether Stop() has been
invoked so that such a race can be prevented.

Fix uber-go#930
Internal Ref: GO-1606

* use sync.Once and also add the check for OnStart hooks

* Apply suggestions from code review

Co-authored-by: Abhinav Gupta <mail@abhinavg.net>

Co-authored-by: Abhinav Gupta <mail@abhinavg.net>
sywhang added a commit to sywhang/fx that referenced this pull request Oct 11, 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.

onStop executed many times
2 participants