-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[browser] make dynamic import cancelable #80257
[browser] make dynamic import cancelable #80257
Conversation
{ | ||
var cts = new CancellationTokenSource(); | ||
cts.Cancel(); | ||
var actualEx = await Assert.ThrowsAsync<JSException>(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs", cts.Token)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is there a way to reliably test that the operation gets cancelled in the middle? Passing an already cancelled token is a trivial case that is optimized in other asynchroonous functions. (and you can use
new CancellationToken(true)
instead of creating a CTS) - Shouldn't it throw
OperationCancelledException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underlying JS dynamic import()
is not cancelable.
The JS promises are rather "abandoned" than really canceled. We only reject the JS promise.
(In general, we don't know what else registered continuation on that promise on JS side)
That creates JavaScript error, not managed error and we marshal it as JSException
consistently with all other JS Errors.
fetch
is bit better because it has AbortController
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pavelsavara Did you tried something like this?
var cts = new CancellationTokenSource();
var exTask = Assert.ThrowsAsync<JSException>(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs", cts.Token));
cts.Cancel();
var actualEx = await exTask;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to the unit test, it works fine
The CI failures of WBT seems to be unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
...ervices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
Show resolved
Hide resolved
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3858241533 |
@pavelsavara backporting to release/7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: make dynamic import cancelable
.git/rebase-apply/patch:26: trailing whitespace.
cts.Cancel();
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
M src/mono/wasm/runtime/invoke-js.ts
Falling back to patching base and 3-way merge...
Auto-merging src/mono/wasm/runtime/invoke-js.ts
CONFLICT (content): Merge conflict in src/mono/wasm/runtime/invoke-js.ts
Auto-merging src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 make dynamic import cancelable
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@pavelsavara an error occurred while backporting to release/7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
Fixes #80028
We will need backport to Net7