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

prevent dependencies from being added after stop #1898

Merged
merged 2 commits into from Mar 21, 2024
Merged

prevent dependencies from being added after stop #1898

merged 2 commits into from Mar 21, 2024

Conversation

tgross
Copy link
Member

@tgross tgross commented Mar 19, 2024

A Nomad user reported an issue where View.poll goroutines were being leaked when using large templates. When the runner's Run method is in-flight and the runner concurrently receives Stop, it's possible for the watcher to stop dependencies via stop and then immediately recreate them. Because the Stop method has returned, the caller will assume that all goroutines have been stopped, and this causes the View.poll goroutines to be leaked. The race condition for this case is very narrow, but is most likely to occur when the user has both a very large number of dependencies, short secret leases, and the Wait configuration is nil.

Add a stopped flag to the Watcher which is set on Stop, and check whether this field has been set before adding a new dependency.

Ref: hashicorp/nomad#20163

@tgross
Copy link
Member Author

tgross commented Mar 19, 2024

Looks like there's some cross-test pollution to figure out here. Working on detangling that now and will mark ready-for-review once I have it fixed. Fixed: when you set the default lease, it's set via sync.Once in the package, so tests can't rely on setting it to specific values. I've fixed this in my test by having the mock Vault response have a specific TTL.

A Nomad user reported an issue where `View.poll` goroutines were being leaked
when using large templates. When the runner's `Run` method is in-flight and the
runner concurrently receives `Stop`, it's possible for the watcher to stop
dependencies via stop and then immediately recreate them. Because the `Stop`
method has returned, the caller will assume that all goroutines have been
stopped, and this causes the `View.poll` goroutines to be leaked. The race
condition for this case is very narrow, but is most likely to occur when the
user has both a very large number of dependencies, short secret leases, and the
`Wait` configuration is nil.

Add a `stopped` flag to the `Watcher` which is set on `Stop`, and check whether
this field has been set before adding a new dependency.
manager/runner_test.go Outdated Show resolved Hide resolved
Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgross tgross merged commit 453869d into main Mar 21, 2024
54 checks passed
@tgross tgross deleted the leaked-poll branch March 21, 2024 13:18
@tgross
Copy link
Member Author

tgross commented Mar 27, 2024

Released in 0.37.4. Updated in Nomad here: hashicorp/nomad#20234

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

Successfully merging this pull request may close these issues.

None yet

2 participants