Return-Path: X-Original-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 50E389C05 for ; Thu, 6 Sep 2012 03:03:10 +0000 (UTC) Received: (qmail 62235 invoked by uid 500); 6 Sep 2012 03:03:09 -0000 Delivered-To: apmail-incubator-callback-dev-archive@incubator.apache.org Received: (qmail 62103 invoked by uid 500); 6 Sep 2012 03:03:09 -0000 Mailing-List: contact callback-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-dev@incubator.apache.org Received: (qmail 61985 invoked by uid 99); 6 Sep 2012 03:03:07 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2012 03:03:07 +0000 Date: Thu, 6 Sep 2012 14:03:07 +1100 (NCT) From: "Jimmy Jarvis (JIRA)" To: callback-dev@incubator.apache.org Message-ID: <549034274.42711.1346900587733.JavaMail.jiratomcat@arcas> In-Reply-To: <1567442393.19746.1346374928107.JavaMail.jiratomcat@arcas> Subject: [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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-1318?page=3Dcom.atlassian.ji= ra.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1344937= 5#comment-13449375 ]=20 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 ID= s. It would be unfortunate overhead to have to reinitialize our native logi= c 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 ign= oring unmatched callbacks. I agree seeing the plugin a Reset or Terminate m= essage 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. =20 > Cordova Callback Logic Not Implemented Correctly - Native Asynchronous C= ompletion Can Call Wrong Logic in Javascript - Requires Non-recurring Uniqu= e 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 async= hronous callback that occurs when the calling context has changed. > PROBLEM: Cordova callback logic can trigger the callback function of an u= nrelated call from a different context. When a call from Javascript is made= , Cordova generates a new callbackId, adds it to the cordova.callbacks arra= y, and passes it along to the native code. Some time later, when the native= code completes the request, it injects javascript to call the callbackSucc= ess or callbackError function. The respective callback handler looks up the= callback attributes from the cordova.callbacks array and executes the orig= inal 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 t= he same callbackId, even though the native code haS not yet completed the p= rior request. This can occur upon a new page load or reload upon an empty h= ref in an anchor tag. A call to native code from page1.html could trigger t= he 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 =3D service + cordova.callbackId++; // BUG: increme= nting Id's can call unrelated callback logic > // WITH THIS LINE > callbackId =3D service + ":" + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxx= xxx'.replace(/[xy]/g, function(c) {var r =3D Math.random()*16|0,v=3Dc=3D=3D= 'x'?r:r&0x3|0x8;return v.toString(16);}); // Generate unique callbackID wit= h 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 administrato= rs For more information on JIRA, see: http://www.atlassian.com/software/jira