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 a bug in on which caused the signal to be disposed of too early. #80

Merged
merged 2 commits into from
Nov 5, 2016

Conversation

andersio
Copy link
Member

@andersio andersio commented Nov 4, 2016

Fixes #77.

The root cause

 		return SignalProducer { observer, compositeDisposable in
  			// ...
  			self.startWithSignal { signal, disposable in
  				compositeDisposable += disposable
 				compositeDisposable += signal.on(...).observe(observer)

The outer input observer was detached by the outer interruption, and this causes the started signal to dispose of itself (no observer + unreachable) under the new lifetime semantics.

Moreover, since CompositeDisposable disposes its inner disposables in the reversed insertion order, the inner producer is interrupted after the said detachment and self-disposal happened.

So in the end, both together caused the injected side effect via on capturing no interrupted event.

The fix

Generally speaking, the disposable of the outer observer to the produced inner signal should not be added to the outer producer's disposable. The termination is already propagated via interrupted.

Note

We might need to review the rest of the operators.

@andersio andersio added this to the 1.0 milestone Nov 4, 2016
@inamiy
Copy link
Contributor

inamiy commented Nov 4, 2016

Thanks for catch!
It seems reversing compositeDisposable += ... also works well (so that self producer's signal is safely interrupted before signal.on(...).observe(observer)'s disposable is being disposed.

        return SignalProducer { observer, compositeDisposable in
            // ...
            self.startWithSignal { signal, disposable in
                compositeDisposable += signal.on(...).observe(observer)
                compositeDisposable += disposable

@andersio
Copy link
Member Author

andersio commented Nov 4, 2016

Disposing the cancel disposable of a produced signal is guaranteed to have interrupted emitted, should the signal not have been terminated.

In other words, adding the observer disposable to the outer disposable is redundant - there is no point to detach from a known-to-be terminated signal.

Moreover, the iteration order is an implementation detail of Bag that should not be depended on unless absolutely necessary, as Bag by contract is an unordered collection.

@andersio
Copy link
Member Author

andersio commented Nov 4, 2016

@ikesyo Would you mind to have a look at why Linux PM test fails? It says toEventually is missing, but it seems the package config of Nimble is fine.

Copy link
Contributor

@mdiep mdiep left a comment

Choose a reason for hiding this comment

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

Looks good to me apart from the linux failures.

@andersio
Copy link
Member Author

andersio commented Nov 5, 2016

Linux test error would be fixed by #81.

@inamiy
Copy link
Contributor

inamiy commented Nov 5, 2016

@andersio I see. Thanks for explanation. LGTM!

@ikesyo
Copy link
Member

ikesyo commented Nov 5, 2016

@andersio Carthage/Checkouts/Nimble submodule would not be related to SwiftPM integration unfortunately. I will take a look at the failure.

@andersio
Copy link
Member Author

andersio commented Nov 5, 2016

@ikesyo I found that 5.0.0 wrapped the async matchers in something like #if _runtime(objc), which seems to be the cause. Had been removed in 5.1.1 though.

@ikesyo
Copy link
Member

ikesyo commented Nov 5, 2016

@andersio That is the reason I checked out a specific commit in .travis.yml: https://github.com/ReactiveCocoa/ReactiveSwift/blob/master/.travis.yml#L85 (#47). See #68 too (I'm waiting a new release of Quick).

@ikesyo ikesyo mentioned this pull request Nov 5, 2016
@andersio andersio merged commit 7ad4b11 into master Nov 5, 2016
@andersio andersio deleted the flatten-interruption branch November 5, 2016 15:56
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.

Inner signal not "interrupted" on outer signal disposal
4 participants