Skip to content

fix: NSInternalInconsistencyException: "No response has been sent for this task" - second attempt#1640

Open
GitToTheHub wants to merge 3 commits intomasterfrom
pr-dont-call-WKURLSchemeTask-didFinish-in-webView-stopURLSchemeTask
Open

fix: NSInternalInconsistencyException: "No response has been sent for this task" - second attempt#1640
GitToTheHub wants to merge 3 commits intomasterfrom
pr-dont-call-WKURLSchemeTask-didFinish-in-webView-stopURLSchemeTask

Conversation

@GitToTheHub
Copy link
Copy Markdown
Contributor

@GitToTheHub GitToTheHub commented Mar 19, 2026

Platforms affected

iOS

Motivation and Context

Description

Testing

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

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-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.24%. Comparing base (a66a862) to head (4bcc6b8).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GitToTheHub
Copy link
Copy Markdown
Contributor Author

@dpogue Would this be right approach? I read the documentation of [WKURLSchemeTask didFinish] where it says:

It also raises an exception if you call it after WebKit calls the webView:stopURLSchemeTask: method of the corresponding handler object.

@dpogue
Copy link
Copy Markdown
Member

dpogue commented Mar 19, 2026

This is essentially reverting the change from #1606 which was an attempt to fix a different NSInternalInconsistencyException from #1605.

It's possible this is the right approach for a stopped task, but then we need to better understand the original issue and how to prevent that error.

@GitToTheHub GitToTheHub changed the title fix: don't call [WKURLSchemeTask didFinish] in webView:stopURLSchemeTask: fix: NSInternalInconsistencyException: "No response has been sent for this task" and revert #1606 Apr 9, 2026
@GitToTheHub GitToTheHub changed the title fix: NSInternalInconsistencyException: "No response has been sent for this task" and revert #1606 fix: NSInternalInconsistencyException: "No response has been sent for this task", revert #1606 Apr 9, 2026
@GitToTheHub GitToTheHub changed the title fix: NSInternalInconsistencyException: "No response has been sent for this task", revert #1606 fix: NSInternalInconsistencyException: "No response has been sent for this task" Apr 9, 2026
- 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
@GitToTheHub
Copy link
Copy Markdown
Contributor Author

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.

@GitToTheHub GitToTheHub changed the title fix: NSInternalInconsistencyException: "No response has been sent for this task" fix: NSInternalInconsistencyException: "No response has been sent for this task" - second attempt Apr 9, 2026
… thread to prevent race conditions

- Generated-By: Claude Sonnet 4.6, GitHub Copilot Chat
@GitToTheHub
Copy link
Copy Markdown
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants