Bug 18634

Summary: Observable.CombineLatest bug on iOS devices.
Product: iOS Reporter: Nicolas VERINAUD <n.verinaud>
Component: GeneralAssignee: Zoltan Varga <vargaz>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+monotouch, rolf, udhams
Priority: Normal    
Version: master   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Project showing the bug.

Description Nicolas VERINAUD 2014-03-28 05:19:34 UTC
Created attachment 6427 [details]
Project showing the bug.

I have spotted a strange bug in Xamarin.iOS with the Reactive Extensions (Rx).

You will find a sample project demonstrating it. The basic idea is that if you use `Observable.CombineLatest` passing an `IObservable<Exception>` as second argument or further, all `Observable.CombineLatest` that follows stop working as expected.

It seems to be related to MonoTouch (compiled for the device) because it happened only ON THE DEVICE (not in the simulator, nor in a CLI app). I also made sure to use the latest version of Rx (using NuGet).

I have tested on my iPhone 5 running iOS 7.1.

Here is my current IDE and Runtime configuration :
=== Xamarin Studio ===

Version 4.2.3 (build 60)
Installation UUID: ecbe2753-d3d6-467e-b753-3a5d76ad9f32
Runtime:
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 7.2.0.2 (Business Edition)
Hash: 58c3efa
Branch: 
Build date: 2014-10-03 18:02:26-0400

=== Build Information ===

Release ID: 402030060
Git revision: 30c4afc300c2a39ec5300851357ce02e49dd217e
Build date: 2014-03-05 22:09:33+0000
Xamarin addins: f8a9589b57c2bfab2ccd73c880e7ad81e3ecf044

=== Operating System ===

Mac OS X 10.8.5
Darwin Jobs.local 12.5.0 Darwin Kernel Version 12.5.0
    Sun Sep 29 13:33:47 PDT 2013
    root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
Comment 1 Udham Singh 2014-03-28 11:06:11 UTC
I have checked this issue with sample attached into bug description and getting the same behavior. Please refer the screencast: http://screencast.com/t/s0ZgbQtgJCj

Application output for simulator: https://gist.github.com/saurabh360/afd6d3252e559ee36fd2
Application output for device: https://gist.github.com/saurabh360/345ebc49c1ee448dfa3a

Environment Info:

=== Xamarin Studio ===

Version 4.2.3 (build 60)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
 Mono 3.2.6 ((no/9b58377)
 GTK+ 2.24.23 theme: Raleigh
 GTK# (2.12.0.0)
 Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1 (5035)
Build 5B45j

=== Xamarin.iOS ===

Version: 7.2.0.2 (Enterprise Edition)
Hash: 58c3efa
Branch: 
Build date: 2014-10-03 18:02:26-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.13.0 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
 Supported Android versions:
  2.1   (API level 7)
  2.2   (API level 8)
  2.3   (API level 10)
  3.1   (API level 12)
  3.2   (API level 13)
  4.0   (API level 14)
  4.0.3 (API level 15)
  4.1   (API level 16)
  4.2   (API level 17)
  4.3   (API level 18)
  4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 402030060
Git revision: 30c4afc300c2a39ec5300851357ce02e49dd217e
Build date: 2014-03-05 22:09:33+0000
Xamarin addins: f8a9589b57c2bfab2ccd73c880e7ad81e3ecf044

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 2 Rolf Bjarne Kvinge [MSFT] 2014-04-02 12:57:42 UTC
Zoltan, can you have a look at this bug?

I've narrowed the sample down further: https://gist.github.com/rolfbjarne/82055b58801645c02f31

The expected behaviour is to get "Subsequent CombineLatest" printed many times. When the bug is present it doesn't show up even once.

For the bug to occur both calls to CombineLatest must use at least 4 arguments (3 IObservable parameters + 1 delegate).

Additionally the argument to Observable.Return must be an object (int works, string or Exception does not).

So this looks like a code-generation/AOT bug on ARM (maybe a register isn't preserved when it should be?)
Comment 3 Zoltan Varga 2014-04-02 16:10:13 UTC
Another testcase without timers:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
			var ret1 = Observable.Return ("1");
			Observable.CombineLatest(ret1, ret1, ret1, (a, b, c) => {
				return true;
			}).Subscribe(_ => {});
			var ret2 = Observable.Return (1);
			Console.WriteLine ("1");
			Observable.CombineLatest(ret2, ret2, ret2, (a, b, c) => {
					Console.WriteLine("HIT");
				return true;
			}).Subscribe(_ => {});
			Console.WriteLine ("2");
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Changing ret2 to Observable.Return("1") makes it work.
Comment 4 Zoltan Varga 2014-04-03 16:44:07 UTC
Fixed in mono master 32860abf6689cd94585cf6095f1bcee5ca06866f.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2014-04-03 16:48:00 UTC
Zoltan, would it be possible to put this in the mono's 3.4 branch?

I'll make a unit test out of it.
Comment 6 Zoltan Varga 2014-04-03 17:07:55 UTC
Its on the branch now as 6272eafb17079cd17129c3a2ed7d891a71485641.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2014-04-04 07:47:05 UTC
Fixed in monotouch/master: 3d306dc3353917adb50f9b84dc57308123135250.

QA: unit test was added as well.
Comment 8 Rolf Bjarne Kvinge [MSFT] 2014-04-04 10:01:09 UTC
Backported to monotouch-7.2.1-branch: cf3917dceb5d50a2b95a24e595f08e363341ffb4