You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Christoph Jerolimov (JIRA)" <ji...@apache.org> on 2012/10/03 11:18:07 UTC

[jira] [Created] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Christoph Jerolimov created CB-1578:
---------------------------------------

             Summary: App crash (while stopping) caused by an unregistered notification handler in CDVConnection
                 Key: CB-1578
                 URL: https://issues.apache.org/jira/browse/CB-1578
             Project: Apache Cordova
          Issue Type: Bug
          Components: iOS
    Affects Versions: 2.0.0, 2.1.0
         Environment: iOS, all versions
XCode, all versions
            Reporter: Christoph Jerolimov
            Assignee: Shazron Abdullah
            Priority: Critical


The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.

This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!

{code}
# Only an example, this error calls selectors on "random memory / objects"!
<Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
{code}

The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.

The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:

https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139

The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.

https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113


To fix this it's enough to add these removeObservers calls again to the dealloc method.

{code}
[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
{code}

In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.

{code}
	[[NSNotificationCenter defaultCenter] removeObserver:self];
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Posted by "Becky Gibson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Becky Gibson resolved CB-1578.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2.0

Fixed with this commit:  https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=commit;h=99b424fb17e9c4623d410fac3fdd6cb31dee5dfe
                
> App crash (while stopping) caused by an unregistered notification handler in CDVConnection
> ------------------------------------------------------------------------------------------
>
>                 Key: CB-1578
>                 URL: https://issues.apache.org/jira/browse/CB-1578
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0, 2.1.0
>         Environment: iOS, all versions
> XCode, all versions
>            Reporter: Christoph Jerolimov
>            Assignee: Becky Gibson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.
> This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!
> {code}
> # Only an example, this error calls selectors on "random memory / objects"!
> <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
> {code}
> The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.
> The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:
> https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
> https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139
> The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.
> https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113
> To fix this it's enough to add these removeObservers calls again to the dealloc method.
> {code}
> [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
> {code}
> In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.
> {code}
> 	[[NSNotificationCenter defaultCenter] removeObserver:self];
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Posted by "Christoph Jerolimov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470266#comment-13470266 ] 

Christoph Jerolimov commented on CB-1578:
-----------------------------------------

Thank you, but i think it's not necessary to add these code also to the CDVConnection and CDVLocalStorage plugin because the dealloc of the parent class CDVPlugin was called automatically.
                
> App crash (while stopping) caused by an unregistered notification handler in CDVConnection
> ------------------------------------------------------------------------------------------
>
>                 Key: CB-1578
>                 URL: https://issues.apache.org/jira/browse/CB-1578
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0, 2.1.0
>         Environment: iOS, all versions
> XCode, all versions
>            Reporter: Christoph Jerolimov
>            Assignee: Becky Gibson
>            Priority: Critical
>
> The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.
> This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!
> {code}
> # Only an example, this error calls selectors on "random memory / objects"!
> <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
> {code}
> The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.
> The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:
> https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
> https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139
> The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.
> https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113
> To fix this it's enough to add these removeObservers calls again to the dealloc method.
> {code}
> [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
> {code}
> In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.
> {code}
> 	[[NSNotificationCenter defaultCenter] removeObserver:self];
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Assigned] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Posted by "Becky Gibson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Becky Gibson reassigned CB-1578:
--------------------------------

    Assignee: Becky Gibson  (was: Shazron Abdullah)
    
> App crash (while stopping) caused by an unregistered notification handler in CDVConnection
> ------------------------------------------------------------------------------------------
>
>                 Key: CB-1578
>                 URL: https://issues.apache.org/jira/browse/CB-1578
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0, 2.1.0
>         Environment: iOS, all versions
> XCode, all versions
>            Reporter: Christoph Jerolimov
>            Assignee: Becky Gibson
>            Priority: Critical
>
> The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.
> This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!
> {code}
> # Only an example, this error calls selectors on "random memory / objects"!
> <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
> {code}
> The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.
> The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:
> https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
> https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139
> The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.
> https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113
> To fix this it's enough to add these removeObservers calls again to the dealloc method.
> {code}
> [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
> {code}
> In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.
> {code}
> 	[[NSNotificationCenter defaultCenter] removeObserver:self];
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Posted by "Becky Gibson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470275#comment-13470275 ] 

Becky Gibson commented on CB-1578:
----------------------------------

yes, I agree it is not necessary but I like to keep the addObserver and removeObserver calls in the same class. If you addObservers in a class you should be thinking about removing and not relying on base class IMHO.  There is no harm in calling removeObserver: self more than once.
                
> App crash (while stopping) caused by an unregistered notification handler in CDVConnection
> ------------------------------------------------------------------------------------------
>
>                 Key: CB-1578
>                 URL: https://issues.apache.org/jira/browse/CB-1578
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0, 2.1.0
>         Environment: iOS, all versions
> XCode, all versions
>            Reporter: Christoph Jerolimov
>            Assignee: Becky Gibson
>            Priority: Critical
>
> The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.
> This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!
> {code}
> # Only an example, this error calls selectors on "random memory / objects"!
> <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
> {code}
> The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.
> The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:
> https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
> https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139
> The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.
> https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113
> To fix this it's enough to add these removeObservers calls again to the dealloc method.
> {code}
> [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
> {code}
> In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.
> {code}
> 	[[NSNotificationCenter defaultCenter] removeObserver:self];
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CB-1578) App crash (while stopping) caused by an unregistered notification handler in CDVConnection

Posted by "Becky Gibson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469748#comment-13469748 ] 

Becky Gibson commented on CB-1578:
----------------------------------

Took your information and did the necessary clean up of notifications in the appropriate dealloc.   Patch is here: https://github.com/becka11y/incubator-cordova-ios/tree/cb1578

Will check in early next week. Shaz did the original work on this and if he is back from leave next week I'd like to give him a chance to review.
                
> App crash (while stopping) caused by an unregistered notification handler in CDVConnection
> ------------------------------------------------------------------------------------------
>
>                 Key: CB-1578
>                 URL: https://issues.apache.org/jira/browse/CB-1578
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0, 2.1.0
>         Environment: iOS, all versions
> XCode, all versions
>            Reporter: Christoph Jerolimov
>            Assignee: Shazron Abdullah
>            Priority: Critical
>
> The class {{CDVConnection}} registered itself as observer for background events {{UIApplicationDidEnterBackgroundNotification}} and {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered these calls, for example in the dealloc method.
> This caused in different type of errors which all ends in an app crash. If a CDVConnection instance was already removed from the memory the selectors onPause and onResume will be called on random other objects which doesn't support this selector (1) or illegal memory access!
> {code}
> # Only an example, this error calls selectors on "random memory / objects"!
> <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50
> {code}
> The code which register the notification could be found at the end of the file in the selector {{[CDVConnection initWithWebView:]}}.
> The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned events. Like you see in line 139:
> https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139
> https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139
> The current HEAD do additionally NOT remove the the event {{kReachabilityChangedNotification}} from line 113 which should result in another new bug in the upcoming version.
> https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113
> To fix this it's enough to add these removeObservers calls again to the dealloc method.
> {code}
> [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
> [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
> {code}
> In generally it's would also be possible to remove the instance in CDVPlugin for all events!? This would allow you to remove many code from many different plugins and ensure that no other plugin forget these cleanup.
> {code}
> 	[[NSNotificationCenter defaultCenter] removeObserver:self];
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira