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

Add timeout and unit to TimeoutException message #6234

Merged

Conversation

artem-zinnatullin
Copy link
Contributor

This is a small enhancement to help with crash/log debugging.

Right now often times you get a stacktrace that points only to RxJava:

java.util.concurrent.TimeoutException
        at
io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutSubscriber.onTimeout(FlowableTimeoutTimed.java:137)
        at
io.reactivex.internal.operators.flowable.FlowableTimeoutTimed$TimeoutTask.run(FlowableTimeoutTimed.java:169)
        at
io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at
io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748) 

Adding timeout and unit values can help find related user code faster.

I'm not advocating for particular message, it can be something even shorter, like $timeout $unit.

It can also be extracted in a method if you see value in that.

@akarnokd
Copy link
Member

akarnokd commented Oct 1, 2018

I'm for better error messages but I'm not convinced a timeout value is generally unique enough in a project that will allow you to locate the flow. Especially when the timeout value comes from configuration and thus it is not prevalent in the source code.

An alternative would be an overload on the operator with a String argument that would be passed onto the exception constructor, tagging the particular source location.

@codecov
Copy link

codecov bot commented Oct 1, 2018

Codecov Report

Merging #6234 into 2.x will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6234      +/-   ##
============================================
- Coverage     98.26%   98.21%   -0.05%     
+ Complexity     6201     6200       -1     
============================================
  Files           667      667              
  Lines         44883    44887       +4     
  Branches       6216     6216              
============================================
- Hits          44103    44088      -15     
- Misses          243      261      +18     
- Partials        537      538       +1
Impacted Files Coverage Δ Complexity Δ
...ernal/operators/flowable/FlowableTimeoutTimed.java 99.18% <100%> (+0.81%) 3 <0> (ø) ⬇️
...rnal/operators/completable/CompletableTimeout.java 100% <100%> (ø) 2 <0> (ø) ⬇️
...va/io/reactivex/internal/util/ExceptionHelper.java 100% <100%> (ø) 18 <1> (+1) ⬆️
...activex/internal/subscribers/FutureSubscriber.java 100% <100%> (ø) 32 <0> (ø) ⬇️
...o/reactivex/internal/observers/FutureObserver.java 87.69% <100%> (ø) 28 <0> (ø) ⬇️
...ivex/internal/observers/BlockingMultiObserver.java 100% <100%> (ø) 24 <0> (ø) ⬇️
...l/operators/observable/ObservableTimeoutTimed.java 100% <100%> (ø) 3 <0> (ø) ⬇️
...tivex/internal/operators/single/SingleTimeout.java 100% <100%> (+1.72%) 2 <1> (ø) ⬇️
...tivex/internal/observers/FutureSingleObserver.java 94.33% <100%> (-3.78%) 24 <0> (-1)
...io/reactivex/subscribers/SerializedSubscriber.java 94.31% <0%> (-4.55%) 25% <0%> (-1%)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ea1e2a...827d1fd. Read the comment docs.

@artem-zinnatullin
Copy link
Contributor Author

I like your suggestion, I still however think that adding timeout and value is a good option for now and for the case when user didn't specify a message.

This will be a "free" improvement for existing users who will just receive it with an update of the library and 0 changes in their code.

Especially when the timeout value comes from configuration and thus it is not prevalent in the source code.

Often times these configurations are traceable, thus knowing the values can be helpful enough.

But still, optional message sounds good to me, I can work on it once we decide on the destiny of this PR

@akarnokd
Copy link
Member

akarnokd commented Oct 1, 2018

Okay, let's have a default message for now, but more like along these lines:

The source did not signal an event for $timeout ${unit.toLowerCase()}(s) and has been terminated.

@artem-zinnatullin
Copy link
Contributor Author

sgtm, implementing

@@ -82,26 +83,24 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() {

@Test
public void shouldTimeoutIfOnNextNotWithinTimeout() {
Subscriber<String> subscriber = TestHelper.mockSubscriber();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below I'm not sure what's the purpose of mocking, TestSubscriber/TestObserver are capable of checking what's needed in these test cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably some v1 hybrid remnant.

@artem-zinnatullin
Copy link
Contributor Author

I've updated the message and added tests, turns out in some cases we didn't check for TimeoutException, now these cases are covered

@vanniktech please take a look again

Copy link
Collaborator

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice even getting rid of some mockito nonsense.

@akarnokd akarnokd merged commit 6126752 into ReactiveX:2.x Oct 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants