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

Fixed the issue that 'zip' calls 'onCompleted' twice #766

Closed
wants to merge 1 commit into from

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Jan 19, 2014

Fixed the issue reported by Vadim Spivak at https://groups.google.com/forum/#!topic/rxjava/79cWTv3TFp0

The original zip implementation may call onCompleted more than once but does not wrap the observer with a SafeObserver. When the observer is an internal observer, zip will break the Rx contract.

This PR wraps the internal observer with a SafeObserver.

@cloudbees-pull-request-builder

RxJava-pull-requests #678 SUCCESS
This pull request looks good

@akarnokd
Copy link
Member

There is a shorter way:
L312: insert if (done) { return; }
L260: insert done = true;

(Original line numbers)

@zsxwing
Copy link
Member Author

zsxwing commented Jan 19, 2014

@akarnokd What if two ItemObservers both execute the codes protected by rwLock.writeLock().tryLock()? observer.onCompleted(); will be called twice.

            @Override
            public void onCompleted() {
                boolean c = false;
                rwLock.readLock().lock();
                try {
                    done = true;
                    c = true;
                } finally {
                    rwLock.readLock().unlock();
                }
                if (rwLock.writeLock().tryLock()) {
                    try {
                        for (ItemObserver<T> io : all) {
                            if (io.queue.isEmpty() && io.done) {
                                observer.onCompleted();
                                cancel.unsubscribe();
                                return;
                            }
                        }
                    } finally {
                        rwLock.writeLock().unlock();
                    }
                }
                if (c) {
                    unsubscribe();
                }
            }

@akarnokd
Copy link
Member

True. It can get complicated, I need to think about it. Otherwise, you could wrap the o2 observer with safe to ensure event semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants