You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Jimmy Jarvis (JIRA)" <ji...@apache.org> on 2012/08/31 03:02:08 UTC

[jira] [Created] (CB-1318) Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Suggested

Jimmy Jarvis created CB-1318:
--------------------------------

             Summary: Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Suggested
                 Key: CB-1318
                 URL: https://issues.apache.org/jira/browse/CB-1318
             Project: Apache Cordova
          Issue Type: Bug
          Components: iOS
    Affects Versions: 2.0.0
            Reporter: Jimmy Jarvis
            Assignee: Shazron Abdullah
            Priority: Critical


This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.

PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.

SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:

// REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
        callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic

// WITH THIS LINE
        callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID


This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.


--
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] [Updated] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Shazron Abdullah updated CB-1318:
---------------------------------

    Fix Version/s: 2.2.0

Late in the cycle for 2.1.0, slating for 2.2.0
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Braden Shepherdson resolved CB-1318.
------------------------------------

    Resolution: Fixed

The randomized version is sufficiently robust to mark this as Fixed.

We can decide to change it to add a timestamp for guaranteed uniqueness, or a linear counter for ease of debugging as a separate issue.
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jim Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Shazron Abdullah reassigned CB-1318:
------------------------------------

    Assignee: Braden Shepherdson  (was: Shazron Abdullah)
    
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Comment Edited] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis edited comment on CB-1318 at 9/6/12 2:04 PM:
----------------------------------------------------------

JSON-P uses a unique callback identifier, similar to the proposed fix above, and is far more reliable and easier to debug than reset with repeating IDs. It would be unfortunate overhead to have to reinitialize our native logic every time a page reloads. The app would become far less responsive, at least for us. If a plugin is a bunch of stubs, it's not an big deal as you say -- however, if it is a longer running setup process ---- I'd prefer ignoring unmatched callbacks. I agree sending the plugin a Reset or Terminate message would enable the plugin authors an opportunity to do proper cleanup on pending requests, but even if they do not, unique ID's (like JSON-P) are a better solution than repeating IDs.
                
      was (Author: jiminyjarvis):
    JSON-P uses a unique callback identifier, similar to the proposed fix above, and is far more reliable and easier to debug than reset with repeating IDs. It would be unfortunate overhead to have to reinitialize our native logic every time a page reloads. The app would be come far less responsive, at least for us. If a plugin is a bunch of stubs, it's not an big deal as you say -- however, if it is a longer running setup process ---- I'd prefer ignoring unmatched callbacks. I agree sending the plugin a Reset or Terminate message would enable the plugin authors an opportunity to do proper cleanup on pending requests, but even if they do not, unique ID's (like JSON-P) are a better solution than repeating IDs.
                  
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Updated] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis updated CB-1318:
-----------------------------

    Summary: Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined  (was: Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Suggested)
    
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Shazron Abdullah commented on CB-1318:
--------------------------------------

Hi Braden,
If you don't mind, since this is more of a multi platform concern (the callback handling is common across all platforms https://github.com/apache/incubator-cordova-js/blob/master/lib/cordova.js#L152) we should have this discussion in the callback-dev mailing list.
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Shazron Abdullah commented on CB-1318:
--------------------------------------

Callback-dev mailing list thread:
http://apache.markmail.org/thread/55jbo3yc6cf6vgl5
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis commented on CB-1318:
----------------------------------

This seems like a pretty critical bug as it's difficult to detect and resolve for anyone without a deep understanding asynchronous logic design. I'd proposed we try and get this fix in and tested as soon as possible. The community of users could be experiencing instability in their code without realizing it or an easy way to reproduce it because of callback latency, especially in network calls.

The problem is that the current callback logic in 2.0.0 enables native code to execute incorrect logic across a page reload. The proposed fix insures native callbacks cannot survive page reloads. Here is a scenario that demonstrates the problem which could be quite common:

1. HTML/JS: Calls native code (gets assigned callbackId = Service1)

2. ------ NATIVE CODE: Begins working on the request (e.g. REST call, which will take 2 - 5 seconds)

3. HTML/JS: Page refreshes or navigates to a new page. This causes the callbackId to reset to zero and all entries in the callbacks array to be cleared (Service1 from Step 1 and pending in Step 2 is now gone)

4. HTML/JS: Calls a different native function (e.g. REST call, Camera, etc. and is assigned Service1 again)

5. ------ NATIVE CODE: Completes pending REST call and makes asynchronous callback to JS using it's callbackId = Service1

6. HTML/JS: Finds the new page's Service1 callbackId in the callbacks array and executes its completion routine, NOT the original REST call's completion routine.

                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Updated] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Andrew Grieve updated CB-1318:
------------------------------

    Component/s: Android
    
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis commented on CB-1318:
----------------------------------

My pleasure and thank you for fixing it. When the patch is release we'll pull our pseudo-GUID out in favor of your patch. Could you please include the Date().getTime() integer (e.g. + 1347566429801) as part of your random number string? To you point, a random number is unlikely to repeat, but this would make it failsafe, completely removing to possibility of a phantom callback. Again, thanks so much for fixing this!
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Braden Shepherdson commented on CB-1318:
----------------------------------------

I'm interested in working on this for 2.2. That means that we need to discuss the approach to solving this problem.

On discussion with Andrew Grieve, we feel the best approach would be to do the following on navigation:
- Blow away the mapping of callback identifiers, effectively canceling all pending callbacks.
- Call a destroy() or similar method on each plugin object, allowing them a chance to cancel pending operations that they have outstanding - network requests and the like. It is not essential that plugins are well-behaved here, it would only result in a bit of wasted effort.
- Destroy each plugin object and recreate it, allowing the plugin to start fresh as though this were the first page loaded.

We feel that simply calling a reset() method on a plugin relies on the plugin authors getting things right and actually cleaning things up to a good state. The above method is more robust, and more in line with the browser model of what a navigation means: the old context is destroyed and a clean slate is used.

Thoughts?
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Andrew Grieve commented on CB-1318:
-----------------------------------

This is something I've been thinking about lately as well. What tipped me off is that in the mobile spec you can start a watch on the compass / accelerometer and do a page change, and you still see logs from the callbacks. I think this was on Android though, so we'll want to verify this problem on both platforms.

I think the fix should either be to recreate all plugins on a navigation or to add a reset method to all of them.

In reality, this bug has been around for a very long time, so it doesn't make sense to rush a fix into this release.
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Comment Edited] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis edited comment on CB-1318 at 9/6/12 2:03 PM:
----------------------------------------------------------

JSON-P uses a unique callback identifier, similar to the proposed fix above, and is far more reliable and easier to debug than reset with repeating IDs. It would be unfortunate overhead to have to reinitialize our native logic every time a page reloads. The app would be come far less responsive, at least for us. If a plugin is a bunch of stubs, it's not an big deal as you say -- however, if it is a longer running setup process ---- I'd prefer ignoring unmatched callbacks. I agree sending the plugin a Reset or Terminate message would enable the plugin authors an opportunity to do proper cleanup on pending requests, but even if they do not, unique ID's (like JSON-P) are a better solution than repeating IDs.
                
      was (Author: jiminyjarvis):
    JSON-P uses a unique callback identifier, similar to the proposed fix above, and is far more reliable and easier to debug than reset with repeating IDs. It would be unfortunate overhead to have to reinitialize our native logic every time a page reloads. The app would be come far less responsive, at least for us. If a plugin is a bunch of stubs, it's not an big deal as you say -- however, if it is a longer running setup process ---- I'd prefer ignoring unmatched callbacks. I agree seeing the plugin a Reset or Terminate message would enable the plugin authors an opportunity to do proper cleanup on pending requests, but even if they do not, unique ID's (like JSON-P) are a better solution than repeating IDs.
                  
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Updated] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Joe Bowser updated CB-1318:
---------------------------

    Remaining Estimate:     (was: 1h)
     Original Estimate:     (was: 1h)
    
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Braden Shepherdson commented on CB-1318:
----------------------------------------

As I've noted elsewhere on JIRA and the mailing list, I've got a general patch for this sitting in my repo. It randomizes the callback numbers so that collision is extremely unlikely.

Thanks for catching this subtle bug!
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis commented on CB-1318:
----------------------------------

JSON-P uses a unique callback identifier, similar to the proposed fix above, and is far more reliable and easier to debug than reset with repeating IDs. It would be unfortunate overhead to have to reinitialize our native logic every time a page reloads. The app would be come far less responsive, at least for us. If a plugin is a bunch of stubs, it's not an big deal as you say -- however, if it is a longer running setup process ---- I'd prefer ignoring unmatched callbacks. I agree seeing the plugin a Reset or Terminate message would enable the plugin authors an opportunity to do proper cleanup on pending requests, but even if they do not, unique ID's (like JSON-P) are a better solution than repeating IDs.
                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Shazron Abdullah
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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] [Comment Edited] (CB-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jimmy Jarvis edited comment on CB-1318 at 9/14/12 7:02 AM:
-----------------------------------------------------------

My pleasure and thank you for fixing it. When the patch is release we'll pull our pseudo-GUID out in favor of your patch. Could you please include the Date().getTime() integer (e.g. + 1347566429801) as part of your random number string? To you point, a random number is unlikely to repeat, but this would make it failsafe, completely removing the possibility of a phantom callback. Again, thanks so much for fixing this!
                
      was (Author: jiminyjarvis):
    My pleasure and thank you for fixing it. When the patch is release we'll pull our pseudo-GUID out in favor of your patch. Could you please include the Date().getTime() integer (e.g. + 1347566429801) as part of your random number string? To you point, a random number is unlikely to repeat, but this would make it failsafe, completely removing to possibility of a phantom callback. Again, thanks so much for fixing this!
                  
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jimmy Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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-1318) Cordova Callback Logic Not Implemented Correctly - Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined

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

Jim Jarvis commented on CB-1318:
--------------------------------

Braden,

Here is the fix we are using:

cordova.ios.js

REPLACE THIS LINE:
callbackId = service + cordova.callbackId++;

WITH THIS LINE:
callbackId = service + ":" + (new Date().getTime()).toString() + "-" + (Math.floor(Math.random()*90000) + 10000).toString(); // Insure context-safe async callbacks

EXAMPLE ID: 1348454513273-31295

The callbackId is still human readable with service name prefix and replayed callbacks are highly unlikely. It's been working for us without any issues for some time now.

                
> Cordova Callback Logic Not Implemented Correctly -  Native Asynchronous Completion Can Call Wrong Logic in Javascript - Requires Non-recurring Unique ID as Outlined
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-1318
>                 URL: https://issues.apache.org/jira/browse/CB-1318
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, iOS
>    Affects Versions: 2.0.0
>            Reporter: Jim Jarvis
>            Assignee: Braden Shepherdson
>            Priority: Critical
>             Fix For: 2.2.0
>
>
> This bug creates very difficult to find execution anomalies for any asynchronous callback that occurs when the calling context has changed.
> PROBLEM: Cordova callback logic can trigger the callback function of an unrelated call from a different context. When a call from Javascript is made, Cordova generates a new callbackId, adds it to the cordova.callbacks array, and passes it along to the native code. Some time later, when the native code completes the request, it injects javascript to call the callbackSuccess or callbackError function. The respective callback handler looks up the callback attributes from the cordova.callbacks array and executes the original caller's completion function. The problem is each page, or reload of a page, resets the callbackId counter to zero and new calls end up reusing the same callbackId, even though the native code haS not yet completed the prior request. This can occur upon a new page load or reload upon an empty href in an anchor tag. A call to native code from page1.html could trigger the completion routine on page2.html because the native code has no context of the change on the other side of the bridge.
> SOLUTION: Replace the incrementing callbackId with a unique identifier to insure only the caller's completion logic will be called. I have done this with a Pseudo-GUID generator. Fix outlined below:
> // REPLACE THIS LINE in both cordova.2.0.0.js and cordova.ios.js
>         callbackId = service + cordova.callbackId++;    // BUG: incrementing Id's can call unrelated callback logic
> // WITH THIS LINE
>         callbackId = service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID with Pseudo-GUID
> This fix insures no code will execute if the caller's context has changed and is a more well formatted callbackId.

--
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