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

1.x: improve ExecutorScheduler worker unsubscription some more #3867

Merged
merged 1 commit into from
Apr 20, 2016

Conversation

davidmoten
Copy link
Collaborator

As per discussion in #3842, there was an outstanding possibility that unsubscription of a Worker would not cancel all tasks waiting in the queue. This PR addresses that possibility. I attempted to provoke the condition in a unit test but didn't manage it. Nethertheless I think this change completes the protection desired in #3842.

I do have mixed feelings about the possible double calling of queue.clear() (once in the run() method and once in the unsubscribe() method. Any preferences?

@akarnokd
Copy link
Member

there was an outstanding possibility that unsubscription of a Worker would not cancel all tasks waiting in the queue.

Tasks are tracked in a separate structure for cancellation, which always happens but maybe not that eagerly and not the same order they were submitted.

You should also keep the original up-front clear() part.

@davidmoten davidmoten force-pushed the unsub-scheduled-tasks branch from 90f8287 to bf202ec Compare April 19, 2016 11:12
@davidmoten
Copy link
Collaborator Author

Thanks @akarnokd, I've updated the PR and squashed commits.

@akarnokd
Copy link
Member

👍

@zsxwing
Copy link
Member

zsxwing commented Apr 19, 2016

there was an outstanding possibility that unsubscription of a Worker would not cancel all tasks waiting in the queue

@davidmoten Could you explain how this will happen and why adding if (!tasks.isUnsubscribed()) { could help? Even if tasks.isUnsubscribed returns false, it may become true after you just check it.

@davidmoten
Copy link
Collaborator Author

@zsxwing sure, you're right that that is possible but that scenario doesn't worry me in that I just consider that as not being able to stop work in progress as opposed to work that is queued. So I guess that's all that is happening here because the check of tasks.isUnsubscribed() at the start of of the loop is all that's required to prevent the issue that I was worried about in #3842. This additional check just firms up not running queued work that has been cancelled.

@zsxwing
Copy link
Member

zsxwing commented Apr 20, 2016

This additional check just firms up not running queued work that has been cancelled.

Sounds like adding isUnsubscribed in an operator?

@davidmoten
Copy link
Collaborator Author

Yep, analagous to that

@zsxwing
Copy link
Member

zsxwing commented Apr 20, 2016

👍

@zsxwing zsxwing merged commit 3439dd8 into ReactiveX:1.x Apr 20, 2016
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.

3 participants