GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 2.x: Fix refCount() connect/subscribe/cancel deadlock by akarnokd · Pull Request #5975 · ReactiveX/RxJava

Conversation

@akarnokd

@akarnokd akarnokd commented Apr 28, 2018

Copy link
Copy Markdown
Member

This PR fixes a deadlock issue with the refCount operator when a subscription leads to a blocking execution while the lock is being held, preventing other subscription or cancellation from executing on other threads.

The bug was discovered as the cause of a reported hang on the Google groups.

The code has been developed in the extensions project where the operator has more features. The overloads supporting these features can be added in a separate enhancement PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@akarnokd
2.x: Fix refCount() connect/subscribe/cancel deadlock
9299d86
@akarnokd akarnokd added Bug 2.x labels Apr 28, 2018
@akarnokd akarnokd added this to the 2.2 milestone Apr 28, 2018
vanniktech
vanniktech approved these changes Apr 28, 2018
View reviewed changes
Comment thread src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java Outdated
public void blockingSourceAsnycCancel() throws Exception {
BehaviorProcessor<Integer> bp = BehaviorProcessor.createDefault(1);

Flowable<Integer> o = bp

@vanniktech vanniktech Apr 28, 2018

Copy link
Copy Markdown
Collaborator

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.

should be f

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codecov

codecov Bot commented Apr 28, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #5975 into 2.x will decrease coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##                2.x   #5975      +/-   ##
===========================================
- Coverage     98.27%   98.2%   -0.07%     
- Complexity     6019    6049      +30     
===========================================
  Files           656     656              
  Lines         44037   44074      +37     
  Branches       6100    6118      +18     
===========================================
+ Hits          43278   43285       +7     
- Misses          224     246      +22     
- Partials        535     543       +8
Impacted Files Coverage Δ Complexity Δ
.../internal/operators/flowable/FlowableRefCount.java 100% <100%> (ø) 22 <22> (+15) ⬆️
...ernal/operators/observable/ObservableRefCount.java 100% <100%> (ø) 22 <22> (+15) ⬆️
...l/operators/observable/ObservableFlatMapMaybe.java 89.54% <0%> (-4.58%) 2% <0%> (ø)
...rnal/operators/flowable/FlowableFlatMapSingle.java 92.93% <0%> (-3.81%) 2% <0%> (ø)
...a/io/reactivex/internal/util/QueueDrainHelper.java 95.83% <0%> (-2.78%) 55% <0%> (-2%)
...tivex/internal/schedulers/TrampolineScheduler.java 96.1% <0%> (-2.6%) 6% <0%> (ø)
...perators/single/SingleFlatMapIterableFlowable.java 95.83% <0%> (-2.5%) 2% <0%> (ø)
...ava/io/reactivex/processors/BehaviorProcessor.java 96.86% <0%> (-2.25%) 60% <0%> (ø)
.../io/reactivex/internal/schedulers/IoScheduler.java 89.24% <0%> (-2.16%) 9% <0%> (ø)
.../io/reactivex/disposables/CompositeDisposable.java 98.14% <0%> (-1.86%) 39% <0%> (-1%)
... and 23 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 be12fe2...53bddc0. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akarnokd
Add more coverage.
a014fad
vanniktech
vanniktech approved these changes Apr 28, 2018
View reviewed changes
akarnokd added 3 commits April 28, 2018 16:27
@akarnokd
Improve logic and coverage.
a7d0653
@akarnokd
Factor out common cleanup code.
e5a6de9
@akarnokd
Fix termination cleanup.
53bddc0
@akarnokd

akarnokd commented Apr 28, 2018

Copy link
Copy Markdown
Member Author

/cc @davidmoten as you devised the previous refCount algorithm.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vanniktech
vanniktech approved these changes Apr 29, 2018
View reviewed changes
@akarnokd
akarnokd merged commit 5b929c4 into ReactiveX:2.x Apr 29, 2018
@akarnokd
akarnokd deleted the RefCountDeadlockFix branch April 29, 2018 08:39
@davidmoten

davidmoten commented Apr 30, 2018

Copy link
Copy Markdown
Collaborator

👍 Great to see that bit of locking removed. I actually had launched into a non-blocking rewrite of the refCount operator a couple of months ago and had it working with current tests but started bringing in tests from 1.x and got a failure or two with some quite unusual tests, then jumped to something else leaving it on my to-do queue. I'll cast another look at the rewrite soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

artem-zinnatullin
artem-zinnatullin reviewed Apr 30, 2018
View reviewed changes

@artem-zinnatullin artem-zinnatullin left a comment

Copy link
Copy Markdown
Contributor

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.

looks good, but comment :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/internal/operators/flowable/FlowableRefCount.java
}

long c = conn.subscriberCount;
if (c == 0L && conn.timer != null) {

@artem-zinnatullin artem-zinnatullin Apr 30, 2018

Copy link
Copy Markdown
Contributor

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.

looks like this condition is only actual for resubscribeBeforeTimeout test

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@artem-zinnatullin artem-zinnatullin Apr 30, 2018

Copy link
Copy Markdown
Contributor

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.

It's strange to see logic and tests for something that user cannot use in RxJava

As you mentioned in PR description, let's maybe expose additional time related refCount api or try to shrink unused code?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@akarnokd akarnokd Apr 30, 2018

Copy link
Copy Markdown
Member Author

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.

Done: #5986.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@akarnokd akarnokd mentioned this pull request Apr 30, 2018
2.x: Add refCount with count & disconnect timeout #5986
Merged
@akarnokd akarnokd mentioned this pull request May 17, 2018
2.1.14 release preparations #6009
Closed
@jared-bot jared-bot mentioned this pull request May 23, 2018
Dependency update: RxJava xmartlabs/bigbang-template#95
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@artem-zinnatullin artem-zinnatullin artem-zinnatullin left review comments
@vanniktech vanniktech vanniktech approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

2.x Bug

Projects

None yet

Milestone

2.2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@akarnokd @davidmoten @artem-zinnatullin @vanniktech
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.