-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
1.x: fix timeout (timed, selector) unsubscribe bug #5660
Conversation
Codecov Report
@@ Coverage Diff @@
## 1.x #5660 +/- ##
===========================================
- Coverage 84.34% 84.2% -0.15%
- Complexity 2888 2889 +1
===========================================
Files 291 290 -1
Lines 18199 18256 +57
Branches 2480 2495 +15
===========================================
+ Hits 15350 15372 +22
- Misses 1983 2001 +18
- Partials 866 883 +17
Continue to review full report at Codecov.
|
* point on. | ||
* @param <T> the value type | ||
*/ | ||
public final class OperatorTimeout<T> extends OperatorTimeoutBase<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is OperatorTimeoutBase
still used somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In OperatorTimeoutWithSelector
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably should have mentioned in my original bug, but this variant of timeout (which uses OperatorTimeoutWithSelector
) also exhibits the same problem:
public final <U, V> Observable<T> timeout(Func0<? extends Observable<U>> firstTimeoutSelector, Func1<? super T, ? extends Observable<V>> timeoutSelector, Observable<? extends T> other)
Can this fix be adapted to cover that variant as well (which we also use)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they were built on the same abstraction. It wasn't part of the initial report and I try to minimize my interaction with 1.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. As I mention above, the new operator actually allows us to solve both of our use cases, so I'm fine with leaving the other operator alone.
|
||
subject.onNext(5L); | ||
|
||
sch.advanceTimeBy(2, TimeUnit.SECONDS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice -- did not know about TestScheduler, very handy.
|
||
consumed++; | ||
|
||
startTimeout(idx + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this correctly, I think there may be a slight behavior difference between this implementation and the existing one. The existing implementation will timeout (and thus switch) if there are 0 calls to onNext
before the timeout. Here I think there needs to be at least 1 call before the timer is set. I'll confirm this and send a test case when I get a chance.
Turns out we actually want both semantics. We're using the other timeout variant mentioned below to get the "have to have at least one message" semantic by having firstTimeoutSelector
return Observable.never()
. If there were a way to get both behaviors with just this operator, that would great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind -- I see the startTimeout
call in call
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this operator I can override call
to make that optional and get the 2 semantics I'm interested in, so this will be perfect. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that it's final
, doh!. I'm assuming that's a standard policy for operators. In that case would it be possible to add a boolean
parameter to the constructor where true
means start the timer on subscribe and false
means don't? Understood if that seems too specialized, but it would save us having to use the more complex operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, no more new features for 1.x, only bugfixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
Posted fix for the selector version as well. |
Thanks -- we're using the new operators in our code base and they are working as expected. |
Great! |
This PR fixes an unsubscribe bug somewhere in the timed
timeout
operator reported in #5657 by implementing it in a algorithmically fresh manner.