Skip to content

Graceful stop of worker services #781

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

Merged
merged 4 commits into from
Mar 26, 2020
Merged

Conversation

danielmarbach
Copy link
Collaborator

Proposed Changes

As discussed in #771 this makes sure any work that is left is executed and stop only exits after the worker has exited.

The reintroduces the necessary evil GetAwaiter().GetResult() on the highest entry level possible to make the underlying call stack async all the way.

The caveats of this have been discussed in the mentioned PR and seemed to have been outweighed against the benefits of finalizing the work.

@danielmarbach
Copy link
Collaborator Author

In additional to that it would be possible to introduce

either

            public void Enqueue(Work work)
            {
                if (_tokenSource.IsCancellationRequested)
                {
                    return;
                }
                _workQueue.Enqueue(work);
                _syncSource.TrySetResult(true);
            }

or

            public void Enqueue(Work work)
            {
                _tokenSource.Token.ThrowIfCancellationRequested();
                _workQueue.Enqueue(work);
                _syncSource.TrySetResult(true);
            }

thoughts?

@danielmarbach danielmarbach mentioned this pull request Mar 26, 2020
@stebet
Copy link
Contributor

stebet commented Mar 26, 2020

Considering that stoppage has been explicitly requested, I'd think the non-throwing options would make more sense, since you probably don't care about any new work being added at that point?

@danielmarbach
Copy link
Collaborator Author

That was also my idea but I didn't want to bias this discussion too much up front

@michaelklishin
Copy link
Contributor

I also think the non-throwing version makes more sense.

@danielmarbach
Copy link
Collaborator Author

One thing though:

Given that this check is in the hotpath and cannot be optimized away do we really want to do this?

@michaelklishin
Copy link
Contributor

That's a good point. I think as long as the previously enqueued work items are processed, we are reasonably safe.

@lukebakken lukebakken added this to the 6.0.0 milestone Mar 26, 2020
@lukebakken lukebakken self-assigned this Mar 26, 2020
@lukebakken
Copy link
Collaborator

I'll review this after #768 / #779

@lukebakken lukebakken merged commit d0f0e6c into rabbitmq:master Mar 26, 2020
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.

4 participants