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

Preserve 'interrupted' state in blocking methods #6904

Closed
CheatEx opened this issue Feb 12, 2020 · 5 comments
Closed

Preserve 'interrupted' state in blocking methods #6904

CheatEx opened this issue Feb 12, 2020 · 5 comments
Labels

Comments

@CheatEx
Copy link

CheatEx commented Feb 12, 2020

I've noted that BlockingMultiObserver#blockingGet() wraps and re-throws InterruptedException. This makes hard to recover interrupted state of a thread. The general convention is to either throw IE as is or restore the interrupted state so downstream code could handle it too.

RxJava seem to partially follow this convention, see #147 and

But not in the most used public methods.

Did you consider restoring interrupted state in blocking operations designed for external use, specifically in Completable, Single, Maybe, Observable blocking* methods?

@akarnokd
Copy link
Member

Did you consider restoring interrupted state

Yes and decided not to in most cases. The trouble is, restoring the interrupted state may lead to further unintended interrupts.

@CheatEx
Copy link
Author

CheatEx commented Feb 13, 2020

further unintended interrupts

Further interrupts are intended. I would even say desired. The point usually is to terminate a thread ASAP.

@akarnokd
Copy link
Member

Do you have a specific problem or are you just reciting some external convention without contextual considerations of RxJava?

@CheatEx
Copy link
Author

CheatEx commented Feb 15, 2020

No, I'm only learning and evaluating RxJ.

So I would really appreciate if you share those contextual considerations. Or maybe point out a resource where I can learn more about RxJavas convention for cancelling and shutdown of blocked threads.

@akarnokd
Copy link
Member

RxJava is about non-blocking operations and cancellation is just another signal that propagates non-blockingly. However, when dealing with external, blocking APIs, cancellation does trigger thread interruption for the purpose to unblock those specific 3rd party calls. This doesn't automatically imply the next 3rd party call should be interrupted immediately just because it happens to run on the same thread.

Here are some past issues regarding similar situations: https://github.com/ReactiveX/RxJava/issues?q=is%3Aissue+interrupt+is%3Aclosed

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

No branches or pull requests

2 participants