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

_marshal_task_to_cs calls complete_task on already completed task #87963

Closed
dlemstra opened this issue Jun 23, 2023 · 6 comments · Fixed by #88326
Closed

_marshal_task_to_cs calls complete_task on already completed task #87963

dlemstra opened this issue Jun 23, 2023 · 6 comments · Fixed by #88326
Assignees
Milestone

Comments

@dlemstra
Copy link
Contributor

Description

We have a project that uses <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> and copies the content of AppBundle to a JavaScript project. This dotnet project contains a lot of libraries and we have an issue were we could not found the root cause for. We are unable to reproduce it in a small project . I am adding the error message here because this might be related:

dotnet.js:14  System.TypeLoadException: Could not find method '.ctor' due to a type load error: Parent class
 failed to load, due to: Failed to load generic parameter 1 assembly:CompanyName.dll type:CompanyClass`2 
member:(null) assembly:CompanyName.dll type:OtherCompanyClass`2 member:(null)

To try to work around this problem we tried an AOT build (RunAOTCompilationAfterBuild). But we then got the following error reported in the console:

An attempt was made to transition a task to a final state when it had already completed.

This seems to be happening because of this call:

runtimeHelpers.javaScriptExports.complete_task(gc_handle, reason, null, undefined);

That is happening after this call:

runtimeHelpers.javaScriptExports.complete_task(gc_handle, null, data, res_converter || _marshal_cs_object_to_cs);
that fails with the following error message:

RuntimeError: null function or function signature mismatch
    at dotnet.wasm:wasm-function[268195]:0x792fb17
    at dotnet.wasm:wasm-function[278722]:0x7d6dd5c
    at invoke_viiiii (dotnet/dotnet.js:14:237182)
    at dotnet.wasm:wasm-function[278817]:0x7d7bda0
    at dotnet.wasm:wasm-function[293]:0x1850ff
    at dotnet.wasm:wasm-function[306692]:0x9bbb73a
    at invoke_vi (dotnet/dotnet.js:14:235216)
    at dotnet.wasm:wasm-function[306970]:0x9bd7ebc
    at dotnet.wasm:wasm-function[306662]:0x9bbad05
    at dotnet.wasm:wasm-function[306599]:0x9bac4f5

Reproduction Steps

We are unable to create a small sample project that can be used to reproduce this issue.

Expected behavior

That the RuntimeError: null function or function signature mismatch error is reported.

Actual behavior

We are getting this error message instead An attempt was made to transition a task to a final state when it had already completed..

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7.0.304
Windows

<OutputType>Exe</OutputType>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 23, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 23, 2023
@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices.JavaScript and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 23, 2023
@radical radical added the arch-wasm WebAssembly architecture label Jun 23, 2023
@ghost
Copy link

ghost commented Jun 23, 2023

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

Issue Details

Description

We have a project that uses <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> and copies the content of AppBundle to a JavaScript project. This dotnet project contains a lot of libraries and we have an issue were we could not found the root cause for. We are unable to reproduce it in a small project . I am adding the error message here because this might be related:

dotnet.js:14  System.TypeLoadException: Could not find method '.ctor' due to a type load error: Parent class
 failed to load, due to: Failed to load generic parameter 1 assembly:CompanyName.dll type:CompanyClass`2 
member:(null) assembly:CompanyName.dll type:OtherCompanyClass`2 member:(null)

To try to work around this problem we tried an AOT build (RunAOTCompilationAfterBuild). But we then got the following error reported in the console:

An attempt was made to transition a task to a final state when it had already completed.

This seems to be happening because of this call:

runtimeHelpers.javaScriptExports.complete_task(gc_handle, reason, null, undefined);

That is happening after this call:

runtimeHelpers.javaScriptExports.complete_task(gc_handle, null, data, res_converter || _marshal_cs_object_to_cs);
that fails with the following error message:

RuntimeError: null function or function signature mismatch
    at dotnet.wasm:wasm-function[268195]:0x792fb17
    at dotnet.wasm:wasm-function[278722]:0x7d6dd5c
    at invoke_viiiii (dotnet/dotnet.js:14:237182)
    at dotnet.wasm:wasm-function[278817]:0x7d7bda0
    at dotnet.wasm:wasm-function[293]:0x1850ff
    at dotnet.wasm:wasm-function[306692]:0x9bbb73a
    at invoke_vi (dotnet/dotnet.js:14:235216)
    at dotnet.wasm:wasm-function[306970]:0x9bd7ebc
    at dotnet.wasm:wasm-function[306662]:0x9bbad05
    at dotnet.wasm:wasm-function[306599]:0x9bac4f5

Reproduction Steps

We are unable to create a small sample project that can be used to reproduce this issue.

Expected behavior

That the RuntimeError: null function or function signature mismatch error is reported.

Actual behavior

We are getting this error message instead An attempt was made to transition a task to a final state when it had already completed..

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7.0.304
Windows

<OutputType>Exe</OutputType>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>

Other information

No response

Author: dlemstra
Assignees: -
Labels:

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

Milestone: -

@radical
Copy link
Member

radical commented Jun 23, 2023

cc @kg @pavelsavara

@pavelsavara
Copy link
Member

Failed to load generic parameter 1 could be trimming problem, reflection problem or some non-wasm native dependency in the DLL preventing the class from loading. To troubleshoot it, I think you could try to create simpler app, where you try to instantiate that type yourself.

already completed task is more interesting from our perspective, if you could give us small sample app to reproduce it. Possibly you are doing something nasty with JS promises ?

@dlemstra
Copy link
Contributor Author

dlemstra commented Jun 24, 2023

Thanks for your quick response. I will try to create a smaller app where this can be reproduced but that won't be an easy task due to the complexity of the library and all it's dependencies. And it also looks like that small sample could be used to diagnose both issues. Adding both <WasmEmitSymbolMap>true</WasmEmitSymbolMap> and <WasmNativeStrip>false</WasmNativeStrip> is telling me that the issue is occuring at the same spot. And I also just did a quick search for _marshal_task_to_cs inside the issues (should have done that earlier) and I found #77122 that mentions something similar. Maybe our code also causes the dotnet.wasm to break and then this issue will occur?

EDIT: The workaround did not work. I was watching something older due to some strange (non browser?) caching issues with the .dll files.

@kg
Copy link
Member

kg commented Jun 24, 2023

already completed task is more interesting from our perspective, if you could give us small sample app to reproduce it. Possibly you are doing something nasty with JS promises ?

Perhaps the process of completing the task (running completion handlers?) is failing, so when we attempt to handle the exception, we go in and try to complete it with the new exception and that fails?

@kg
Copy link
Member

kg commented Jun 24, 2023

already completed task is more interesting from our perspective, if you could give us small sample app to reproduce it. Possibly you are doing something nasty with JS promises ?

Perhaps the process of completing the task (running completion handlers?) is failing, so when we attempt to handle the exception, we go in and try to complete it with the new exception and that fails?

Yes, looking at

value.then(data => {
if (MonoWasmThreads)
settleUnsettledPromise();
runtimeHelpers.javaScriptExports.complete_task(gc_handle, null, data, res_converter || _marshal_cs_object_to_cs);
teardown_managed_proxy(holder, gc_handle); // this holds holder alive for finalizer, until the promise is freed, (holding promise instead would not work)
}).catch(reason => {
if (MonoWasmThreads)
settleUnsettledPromise();
runtimeHelpers.javaScriptExports.complete_task(gc_handle, reason, null, undefined);
teardown_managed_proxy(holder, gc_handle); // this holds holder alive for finalizer, until the promise is freed
I think that's what happened here. The way it's written, if we fail during complete_task or the call after it, we will attempt to complete the task again. We should either swallow the exception caused by a second task completion, or put in some logic to detect that it's already completed.

@pavelsavara pavelsavara self-assigned this Jun 26, 2023
@pavelsavara pavelsavara removed the untriaged New issue has not been triaged by the area owner label Jun 26, 2023
@pavelsavara pavelsavara added this to the 8.0.0 milestone Jun 26, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 3, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 4, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants