spx-ian-huynh opened a new issue, #1605:
URL: https://github.com/apache/cordova-ios/issues/1605

   # Bug Report
   
   ## Problem
   App crashes happening due to race condition in CDVURLSchemeHandler
   ### What is expected to happen?
   URL scheme tasks started by CDVURLSchemeHandler should always receive a 
response - without crashing the app.
   This worked correctly in cordova-ios 7.1.1.
   
   
   ### What does actually happen?
   After upgrading from cordova-ios 7.1.1 to 8.0.0, the app crashes on startup 
with:
   ```
   Fatal Exception: NSInternalInconsistencyException
   No response has been sent for this task
   CDVURLSchemeHandler.m:169
   __50-[CDVURLSchemeHandler webView:startURLSchemeTask:]_block_invoke
   ```
   
   
   ## Information
   I am running a "hosted web app" pattern where the local page hosted by 
WKWebView quickly navigates to an external url using `window.location.replace`. 
I believe this app crash happens due to a race condition in 
`CDVURLSchemeHandler webView:startURLSchemeTask` and switching to the external 
URL.
   
   In 
[7.1.1](https://github.com/apache/cordova-ios/blob/rel/7.1.1/CordovaLib/Classes/Public/CDVURLSchemeHandler.m)
 The file read and response is sent back to WebKit in the same call, all on the 
main thread.
   
   In 
[8.0.0](https://github.com/apache/cordova-ios/blob/rel/8.0.0/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVURLSchemeHandler.m),
 this is done in a background thread `    [self.viewController.commandDelegate 
runInBackground:^{`.
   I suspect when WebKit is cancelling the task due to url change, there is a 
chance of no response being returned:
   
   1. startURLSchemeTask: is called — the task is added to handlerMap and the 
background block is enqueued (but not yet running)
   2. The web view navigates away (e.g. window.location.replace() to an 
external URL), or the page simply cancels the request
   3. WebKit calls stopURLSchemeTask:, which removes the task from handlerMap
   4. The background block finally executes — every taskActive: check returns 
NO because the task was removed from the map
   5. No response is ever sent (didReceiveResponse:, didFailWithError:, and 
didFinish are all skipped)
   6. WebKit throws NSInternalInconsistencyException: "No response has been 
sent for this task"
   
   
   ### Environment, Platform, Device
   
   - cordova-ios: 8.0.0 (worked on 7.1.1)
   - cordova: 13.0.0
   - iOS: 17+
   - Device: iPhone (reproducible on both physical devices and simulators)
   
   
   
   ### Version information
   
   - cordova 13.0.0
   - cordova-ios 8.0.0
   
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to