Skip to content
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

Merged
merged 3 commits into from
Jan 6, 2023

Conversation

pavelsavara
Copy link
Member

Fixes #80028

We will need backport to Net7

@pavelsavara pavelsavara added this to the 7.0.x milestone Jan 5, 2023
@pavelsavara pavelsavara requested a review from maraf January 5, 2023 19:35
@pavelsavara pavelsavara self-assigned this Jan 5, 2023
@ghost
Copy link

ghost commented Jan 5, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #80028

We will need backport to Net7

Author: pavelsavara
Assignees: pavelsavara
Labels:

arch-wasm, area-System.Runtime.InteropServices.JavaScript

Milestone: 7.0.x

@teo-tsirpanis teo-tsirpanis modified the milestones: 7.0.x, 8.0.0 Jan 5, 2023
{
var cts = new CancellationTokenSource();
cts.Cancel();
var actualEx = await Assert.ThrowsAsync<JSException>(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs", cts.Token));
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

@maraf maraf Jan 6, 2023

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;

Copy link
Member Author

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

@pavelsavara pavelsavara marked this pull request as ready for review January 6, 2023 10:35
@pavelsavara
Copy link
Member Author

The CI failures of WBT seems to be unrelated.

Copy link
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@pavelsavara pavelsavara merged commit 045db5d into dotnet:main Jan 6, 2023
@pavelsavara
Copy link
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3858241533

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

@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!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

@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.

pavelsavara added a commit to pavelsavara/runtime that referenced this pull request Jan 6, 2023
carlossanlop pushed a commit that referenced this pull request Jan 12, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 6, 2023
@pavelsavara pavelsavara deleted the browser_ImportAsync_cancelable branch September 2, 2024 15:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canceling JSHost.ImportAsync fails because dynamic_import in invoke-js.ts is not cancelable
4 participants