fix: NSInternalInconsistencyException: "No response has been sent for this task" - second attempt#1640
Conversation
didFinish]` in `webView:stopURLSchemeTask:`` - Calling `[WKURLSchemeTask didFinish]` in `webView:stopURLSchemeTask:` will raise the exception `NSInternalInconsistencyException - This task has already been stopped` - That an exception is raised in this situation is also documented in the Apple documentation for `WKURLSchemeTask didFinish`: https://developer.apple.com/documentation/webkit/wkurlschemetask/didfinish()?language=objc - Fixes #1638 - Generated-By: GPT-5.3-Codex, GitHub Copilot Chat
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1640 +/- ##
=======================================
Coverage 80.24% 80.24%
=======================================
Files 17 17
Lines 5159 5159
=======================================
Hits 4140 4140
Misses 1019 1019 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@dpogue Would this be right approach? I read the documentation of [WKURLSchemeTask didFinish] where it says:
|
[WKURLSchemeTask didFinish] in webView:stopURLSchemeTask:NSInternalInconsistencyException: "No response has been sent for this task" and revert #1606
NSInternalInconsistencyException: "No response has been sent for this task" and revert #1606NSInternalInconsistencyException: "No response has been sent for this task", revert #1606
NSInternalInconsistencyException: "No response has been sent for this task", revert #1606NSInternalInconsistencyException: "No response has been sent for this task"
- Resolve file errors and range validation before background execution - Send the URL scheme response before queuing background reads - Exit early when task is no longer active and close the file handle
|
I tried to create a fix with AI based on #1605 where some things are not executed any more on the background thread, but am not sure if this brings new errors. I tested the changes on an iOS 26.4 simulator in a production app. I get one time a failure in my JavaScript that an Object could not be found and one time that an image could not be loaded. This happend after some runs in XCode. If this changes are here are not helpfull I will close the PR. |
NSInternalInconsistencyException: "No response has been sent for this task"NSInternalInconsistencyException: "No response has been sent for this task" - second attempt
… thread to prevent race conditions - Generated-By: Claude Sonnet 4.6, GitHub Copilot Chat
|
Hi @dpogue, I dug deeper in this issue and the solution seems to be to call all WKURLSchemeTask callbacks on the main thread to prevent race conditions. I ran multiple times a production app on XCode on an iOS 18.5 and iOS 26.4 simulator and got no issues. Now it needs to verify if this fixes the original issue on #1605. Do you think these changes are good? |
Platforms affected
iOS
Motivation and Context
webView:startURLSchemeTask:and also:NSInternalInconsistencyException - This task has already been stopped, because[WKURLSchemeTask didFinish]cannot be called inwebView:stopURLSchemeTask:, which is documented by Apple: https://developer.apple.com/documentation/webkit/wkurlschemetask/didfinish()?language=objctestStartURLSchemeTaskSendsResponseBeforeBackgroundWorktestStopURLSchemeTaskDoesNotFinishStoppedTasktestMissingFileFailsBeforeBackgroundWorkDescription
Testing
Checklist
(platform)if this change only applies to one platform (e.g.(android))