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

Add timeout to rungroup shutdown #1481

Merged

Conversation

RebeccaMahany
Copy link
Contributor

@RebeccaMahany RebeccaMahany commented Nov 29, 2023

Ensure that the rungroup will still exit in a timely manner even if a rungroup actor a) doesn't interrupt in a timely manner or b) doesn't terminate its execution function in a timely manner. This prevents any rungroup actor from holding launcher in a suspended state, where it isn't doing anything but also isn't exiting in order to reload itself.

Relates to #1205

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I think this is okay. Need to chew on it a little, I think it has surprising complexity

e := <-errors
level.Debug(g.logger).Log("msg", "successfully interrupted actor", "actor", e.errorSourceName, "index", i)
select {
case <-timeoutTimer.C:
Copy link
Contributor

@directionless directionless Nov 30, 2023

Choose a reason for hiding this comment

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

I think this case potentially leaks goroutines, which might leave a zombie process? Might be better than hanging, might need a bigger hammer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will in the case of an autoupdate where we're reloading launcher, yeah -- that seemed preferable to hanging. The bigger hammer I can think of is just os.Exit and let launchctl/systemctl/service manager restart launcher, but I know we've been hesitant to do that in the past.

@@ -65,15 +73,39 @@ func (g *Group) Run() error {
level.Debug(g.logger).Log("msg", "received interrupt error from first actor -- shutting down other actors", "err", initialActorErr)

// Signal all actors to stop.
numActors := int64(len(g.actors))
interruptWait := semaphore.NewWeighted(numActors)
Copy link
Contributor

Choose a reason for hiding this comment

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

semaphore.NewWeighted is interesting as compared to a waitgroup. I think it's good, though a little harder to think about all the edges.

Maybe cleaner than the channels I used for osquery/osquery-go#108, less sure about perf. But that's not a real concern here.

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I think it's good to try.

It feels a little weird, because this rungroup code has all this shutdown/cleanup logic hiding in the start method. But that's where it's always been, and it seems fine

@RebeccaMahany RebeccaMahany added this pull request to the merge queue Dec 4, 2023
Merged via the queue into kolide:main with commit f64926b Dec 4, 2023
24 checks passed
@RebeccaMahany RebeccaMahany deleted the becca/rungroup-shutdown-timeout branch December 4, 2023 14:54
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