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

Question: Why a running computation thread got interrupted while window is finished #6672

Closed
zubchenok opened this issue Oct 16, 2019 · 3 comments · Fixed by #6674
Closed

Comments

@zubchenok
Copy link

Why an active computation thread got interrupted while window is finished?

        Observable
            .intervalRange(0, 2, 0, 1, TimeUnit.SECONDS)
            .window(1, TimeUnit.SECONDS)
            .doOnNext(i -> {
                long start = System.currentTimeMillis();
                while (System.currentTimeMillis() < start+1500) {
                }
                if (Thread.interrupted()) {
                    System.out.println("WTF? Thread is interrupted!");
                }
            })
            .ignoreElements()
            .blockingAwait();

Is it a bug?

@akarnokd
Copy link
Member

This is a shortcoming of the window operator that cancels the timer before terminating, which interrupts the long running code in doOnNext.

A workaround would be to move the computation to yet another thread with observeOn so that the interrupt won't reach it.

I'll look into the termination and timer cancellation ordering to avoid such confusing interrupts.

@akarnokd akarnokd added this to the 3.0 milestone Oct 16, 2019
@zubchenok
Copy link
Author

Could you fix it for 2.x too?

@akarnokd
Copy link
Member

If it can be fixed, both 2.x and 3.x will receive the fix.

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

Successfully merging a pull request may close this issue.

2 participants