Returning 'null' for SelectMany selector results in a very confusing call stack
-
16 เมษายน 2555 3: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 เมษายน 2555 4:07
ตอบทั้งหมด
-
16 เมษายน 2555 4: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 เมษายน 2555 3:57
- ทำเครื่องหมายเป็นคำตอบโดย Bart De Smet [MSFT]Owner 20 เมษายน 2555 20:37
-
19 เมษายน 2555 3: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!