Closed
Description
hi,
i have a question that's similar to #4863, but a bit simpler. i am running into a strange issue that i have been able to simplify to a simple test case - what’s happening is, sometimes, by the time my most downstream method is called, the thread is interrupted (which causes issues because the code i call there bails if the thread is interrupted).
i've been able to simplify the code and repro using this:
private Single<ArrayList<Integer>> fakeDataPiece() {
return Single.fromCallable(() -> {
Thread.sleep(500);
return new ArrayList<Integer>();
}).subscribeOn(Schedulers.io());
}
private Single<BookmarkData> fakeGetData() {
return Single.zip(fakeDataPiece(), fakeDataPiece(), fakeDataPiece(),
(integers, integers2, integers3) ->
new BookmarkData(new ArrayList<>(), new ArrayList<>(), new ArrayList<>()))
.subscribeOn(Schedulers.io());
}
public Single<Uri> exportBookmarksObservable() {
return fakeGetData()
.flatMap(bookmarkData -> Single.just(exportBookmarks(bookmarkData)))
.subscribeOn(Schedulers.io());
}
by the time exportBookmarks
is called, in many cases, Thread.currentThread().isInterrupted()
returns true
.
my question is: why is the thread interrupted? (i am curious as to whether this is expected or if there is something i am misunderstanding or doing wrong).
observations:
- if i explicitly remove all the
subscribeOn
s except for the one inexportBookmarksObservable
, then i don’t see the issue (though it does change the behavior a bit in the sense that, with this, all workers are run on the same thread as opposed to each piece of work happening on a potentially different thread). - if i add a
doOnSuccess
infakeGetData()
, i find the thread is interrupted (and is the same thread thatexportBookmarks
gets called on, while also being interrupted). this also is the same as one of thefakeDataPiece
threads, which, at the time of its completion, is not interrupted. - calling
Thread.interrupted()
as suggested in Get RxCachedThreadScheduler-n when calling Disposable.dispose() #4863 also fixes the problem.
i am using RxJava 2.0.4 - thanks!