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

.timeout with small value on Single does not emit error. RxJava 2.2.21 #7514

Closed
truebden opened this issue Jan 16, 2023 · 3 comments · Fixed by #7515
Closed

.timeout with small value on Single does not emit error. RxJava 2.2.21 #7514

truebden opened this issue Jan 16, 2023 · 3 comments · Fixed by #7515

Comments

@truebden
Copy link

truebden commented Jan 16, 2023

Recently I notices a problem when using Single.timeout with a value really small. So in the snippet bellow you will see 0 nanoseconds, but it also happens with 10 nanoseconds. So also values > 0.
The problem is, that in such a case, the error is no always emitted.

		for (int i = 0; i < 10000000; i++) {
			final int y = i;
			final CountDownLatch latch = new CountDownLatch(1);
			Single.never()
					.timeout(0, TimeUnit.NANOSECONDS, Schedulers.computation())
					.subscribe(v -> {}, e -> {
						System.out.println("timeout " + y);
						latch.countDown();
					});
			if (!latch.await(1, TimeUnit.SECONDS)) {
				throw new IllegalStateException("Timeout was not happening!");
			}
		}

The workaround so far for me is to use a Single.timer instead.

		for (int i = 0; i < 10000000; i++) {
			final int y = i;
			final CountDownLatch latch = new CountDownLatch(1);
			Single.amb(Arrays.asList(Single.never(), Single.timer(0, TimeUnit.NANOSECONDS, Schedulers.computation()).doOnSuccess(l -> {
				throw new TimeoutException();
			})))
					.subscribe(v -> {}, e -> {
						System.out.println("timeout " + y);
						latch.countDown();
					});
			if (!latch.await(1, TimeUnit.SECONDS)) {
				throw new IllegalStateException("Timeout was not happening!");
			}
		}

The above snippets take like 2-3 minute to run in the success case. Most of the time the first one fails during that time, but sometimes also succeeds.
I tested it also with Observable, but could not notice the problematic behavior.

Do you have an idea where this comes from?

@akarnokd
Copy link
Member

Very weird. Only Single.timeout fails this way, other components work. Also present in 3.x. I'll have to investigate further.

@akarnokd akarnokd added this to the 3.1-support milestone Jan 16, 2023
@akarnokd
Copy link
Member

Found the bug. Note that 2.x is no longer maintained so the fix will only go to 3.1.x.

@truebden
Copy link
Author

thank you a lot! The upgrade to version 3 should be done anyway.

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