{"action":"created","issue":{"url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/1414","repository_url":"https://api.github.com/repos/MvvmCross/MvvmCross","labels_url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/1414/labels{/name}","comments_url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/1414/comments","events_url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/1414/events","html_url":"https://github.com/MvvmCross/MvvmCross/issues/1414","id":172315152,"number":1414,"title":"NullReferenceException in MvxPathSourceStep.ClearPathSourceBinding","user":{"login":"softlion","id":190756,"avatar_url":"https://avatars.githubusercontent.com/u/190756?v=3","gravatar_id":"","url":"https://api.github.com/users/softlion","html_url":"https://github.com/softlion","followers_url":"https://api.github.com/users/softlion/followers","following_url":"https://api.github.com/users/softlion/following{/other_user}","gists_url":"https://api.github.com/users/softlion/gists{/gist_id}","starred_url":"https://api.github.com/users/softlion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/softlion/subscriptions","organizations_url":"https://api.github.com/users/softlion/orgs","repos_url":"https://api.github.com/users/softlion/repos","events_url":"https://api.github.com/users/softlion/events{/privacy}","received_events_url":"https://api.github.com/users/softlion/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-21T10:41:29Z","updated_at":"2016-10-04T20:36:29Z","closed_at":null,"body":"I've stumbled upon an interesting crash today. The crash occured in ClearPathSourceBinding. This is the first time it crashes, in 3 months usage of the app.\r\n\r\n        private void ClearPathSourceBinding()\r\n        {\r\n            if (this._sourceBinding != null)\r\n            {\r\n                this._sourceBinding.Changed -= this.SourceBindingOnChanged;\r\n                this._sourceBinding.Dispose();\r\n                this._sourceBinding = null;\r\n            }\r\n        }\r\n\r\nSo the only way this can crash, is because it is executed twice in 2 concurrent tasks.\r\nThe stacktrace was:\r\n\r\n    MvxPathSourceStep.OnDataContextChanged\r\n    MvxSourceStep.DataContext (setter)\r\n    MvxFullBinding.DataContext (setter)\r\n    MvxTaskBasedBindingContext.OnDataContextChange\r\n    Task.Execute (no information from where it has been created)\r\n\r\nThis information is not enough to find the root cause of this problem: i don't know which binding is concerned.\r\n\r\nIn OnDataContextChange, the DataContext setter is not called from a Task. It is called directly from the DataContext setter. But inside OnDataContextChange are called DataContext setters from bindings.\r\nThis should mean it is called from inside the Task of OnDataContextChange.\r\n\r\nThis means a lock should be added around the code inside MvxPathSourceStep.OnDataContextChanged\r\n\r\n       private object syncLock = new object();\r\n\r\n        protected override void OnDataContextChanged()\r\n        {\r\n            lock(syncLock) {\r\n                this.ClearPathSourceBinding();\r\n                this._sourceBinding = this.SourceBindingFactory.CreateBinding(this.DataContext, this.Description.SourcePropertyPath);\r\n                if (this._sourceBinding != null)\r\n                {\r\n                    this._sourceBinding.Changed += this.SourceBindingOnChanged;\r\n                }\r\n            }\r\n            base.OnDataContextChanged();\r\n        }\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/comments/251505476","html_url":"https://github.com/MvvmCross/MvvmCross/issues/1414#issuecomment-251505476","issue_url":"https://api.github.com/repos/MvvmCross/MvvmCross/issues/1414","id":251505476,"user":{"login":"kjeremy","id":4325700,"avatar_url":"https://avatars.githubusercontent.com/u/4325700?v=3","gravatar_id":"","url":"https://api.github.com/users/kjeremy","html_url":"https://github.com/kjeremy","followers_url":"https://api.github.com/users/kjeremy/followers","following_url":"https://api.github.com/users/kjeremy/following{/other_user}","gists_url":"https://api.github.com/users/kjeremy/gists{/gist_id}","starred_url":"https://api.github.com/users/kjeremy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjeremy/subscriptions","organizations_url":"https://api.github.com/users/kjeremy/orgs","repos_url":"https://api.github.com/users/kjeremy/repos","events_url":"https://api.github.com/users/kjeremy/events{/privacy}","received_events_url":"https://api.github.com/users/kjeremy/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T20:36:29Z","updated_at":"2016-10-04T20:36:29Z","body":"I don't quite understand how you're getting into `ClearPathSourceBinding()` multiple times for the same object.  Do we need to start passing `CancellationToken`s around if we're in the middle of altering a `DataContext` to cancel all subsequent tasks?  Where does that leave child bindings?"}}
{"actor":{"display_login":"kjeremy"}}