Returning 'null' for SelectMany selector results in a very confusing call stack
-
יום שני 16 אפריל 2012 03:45
While developing an application using ReactiveUI 3.1, I'm running into a crash in Rx that I'm really struggling to debug. Check out https://github.com/play/play-windows on the "enable-pusher" branch (I've mirrored the code at http://cl.ly/3V0q3a3N0y3p1D3Q3A0J if Git's not your thing). Run theNavigatingToPlayWithCredsShouldStayOnPlay XUnit test, and you'll get the following crash:
System.NullReferenceException occurred HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=System.Reactive.Linq StackTrace: at System.Reactive.Linq.Observαble.SelectMany`2._.SubscribeInner(IObservable`1 inner) at System.Reactive.Linq.Observαble.SelectMany`2._.OnNext(TSource value) at System.Reactive.Observer`1.OnNext(T value) at System.Reactive.Subjects.Subject`1.OnNext(T value) at System.Reactive.Linq.Observαble.AsObservable`1._.OnNext(TSource value) at System.Reactive.Linq.Observαble.Do`1._.OnNext(TSource value) at System.Reactive.Linq.Observαble.Concat`1._.OnNext(TSource value) at System.Reactive.Linq.Observαble.ToObservable`1._.LoopRec(State state, Action`1 recurse) at System.Reactive.Concurrency.Scheduler.<>c__DisplayClass3a`1.<InvokeRec1>b__37(TState state1) at System.Reactive.Concurrency.Scheduler.InvokeRec1[TState](IScheduler scheduler, Pair`2 pair) at System.Reactive.Concurrency.ImmediateScheduler.Schedule[TState](TState state, Func`3 action) at System.Reactive.Concurrency.Scheduler.Schedule[TState](IScheduler scheduler, TState state, Action`2 action) at System.Reactive.Linq.Observαble.ToObservable`1._.Run() at System.Reactive.Linq.Observαble.ToObservable`1.Run(IObserver`1 observer, IDisposable cancel, Action`1 setSink) at System.Reactive.Producer`1.Subscribe(IObserver`1 observer) at System.Reactive.TailRecursiveSink`1.<MoveNext>b__3() at System.Reactive.Concurrency.AsyncLock.Wait(Action action) at System.Reactive.TailRecursiveSink`1.MoveNext() at System.Reactive.TailRecursiveSink`1.<Run>b__0(Action self) at System.Reactive.Concurrency.Scheduler.<Schedule>b__2f(Action`1 _action, Action`1 self) at System.Reactive.Concurrency.Scheduler.<>c__DisplayClass3a`1.<InvokeRec1>b__37(TState state1) at System.Reactive.Concurrency.Scheduler.InvokeRec1[TState](IScheduler scheduler, Pair`2 pair) at System.Reactive.Concurrency.ImmediateScheduler.Schedule[TState](TState state, Func`3 action) at System.Reactive.Concurrency.Scheduler.Schedule[TState](IScheduler scheduler, TState state, Action`2 action) at System.Reactive.Concurrency.Scheduler.Schedule(IScheduler scheduler, Action`1 action) at System.Reactive.TailRecursiveSink`1.Run(IEnumerable`1 sources) at System.Reactive.Linq.Observαble.Concat`1.Run(IObserver`1 observer, IDisposable cancel, Action`1 setSink) at System.Reactive.Producer`1.Subscribe(IObserver`1 observer) at System.Reactive.Linq.Observαble.Do`1.Run(IObserver`1 observer, IDisposable cancel, Action`1 setSink) at System.Reactive.Producer`1.Subscribe(IObserver`1 observer) at System.Reactive.Linq.Observαble.AsObservable`1.Run(IObserver`1 observer, IDisposable cancel, Action`1 setSink) at System.Reactive.Producer`1.Subscribe(IObserver`1 observer) at System.Reactive.Subjects.ConnectableObservable`2.Connect() at Play.ViewModels.PlayViewModel.<>c__DisplayClassa.<.ctor>b__0() in c:\Users\Administrator\Desktop\Play\Play\ViewModels\PlayViewModel.cs:line 107 InnerException:I'm not sure how to debug crashes like this, I've tried to "rearrange" the code several times and I still end up crashing somewhere in Rx. Any ideas?
- נערך על-ידי Paul C Betts יום שני 16 אפריל 2012 04:07
כל התגובות
-
יום שני 16 אפריל 2012 04:06
It's almost guaranteed that once I make a post to the Rx forums, I immediately discover the bug and it's in my own code :)
This happens when you return null in a SelectMany selector (i.e. someObservable.SelectMany(x => null), though in my app's case it wasn't nearly as obvious). Perhaps Rx should add some null guards that would aide in debugging, as this call stack is pretty difficult to figure out what's going on.
- הוצע כתשובה על-ידי Mr. Javaman II יום חמישי 19 אפריל 2012 03:57
- סומן כתשובה על-ידי Bart De Smet [MSFT]Owner יום שישי 20 אפריל 2012 20:37
-
יום חמישי 19 אפריל 2012 03:57Hey Paul, I too have done the same thing. It's almost like the posting itself kicks me into another dimension...
JP Cowboy Coders Unite!