Skip to content

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.
@tgross tgross marked this pull request as ready for review March 19, 2024 17:30
@tgross tgross added the bug label Mar 19, 2024
@tgross tgross requested review from shoenig and angrycub March 19, 2024 17:45
Copy link
Contributor

@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
@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.

2 participants