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

[Wasm][Profiled AOT] Error: TaskT_TransitionToFinal_AlreadyCompleted #77122

Open
jeromelaban opened this issue Oct 17, 2022 · 10 comments
Open

[Wasm][Profiled AOT] Error: TaskT_TransitionToFinal_AlreadyCompleted #77122

jeromelaban opened this issue Oct 17, 2022 · 10 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono area-System.Net.Http needs-author-action An issue or pull request that requires more info or actions from the author.
Milestone

Comments

@jeromelaban
Copy link
Contributor

jeromelaban commented Oct 17, 2022

Description

When running the code below, the app crashes when built with an AOT profile. When running with the interpreter, or without a profile, the app runs properly.

Reproduction Steps

When running the following code using profiled AOT:

public static class Program
{
    static async Task Main(string[] args)
    {
        await Fetch();
    }

    private static async Task Fetch()
    {
        try
        {
            var client = new System.Net.Http.HttpClient()
            {
                DefaultRequestHeaders = { { "origin", "WindowsCalculator" } }
            };

            var r = await client.GetAsync(new Uri("https://cors-anywhere.herokuapp.com/https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png"));
            Console.WriteLine($"Got Response");
            var c = await r.Content.ReadAsByteArrayAsync();
            Console.WriteLine($"Got {c.Length} bytes");
        }
        catch (Exception e)
        {
            Console.WriteLine($"Failure: " + e);
        }
    }
}

Profile: aot.zip
Full repro: https://github.com/jeromelaban/Wasm.Samples/tree/master/AotIssueMismatch77122

Expected behavior

No crash, bytes are reported.

Actual behavior

Uncaught (in promise) Error: TaskT_TransitionToFinal_AlreadyCompleted
    at marshal_exception_to_js (dotnet.js:5:53508)
    at invoke_method_and_handle_exception (dotnet.js:5:76910)
    at runtimeHelpers.javaScriptExports.complete_task (dotnet.js:5:81214)
    at dotnet.js:5:39700
marshal_exception_to_js	@	dotnet.js:5
invoke_method_and_handle_exception	@	dotnet.js:5
runtimeHelpers.javaScriptExports.complete_task	@	dotnet.js:5
(anonymous)	@	dotnet.js:5
Promise.catch (async)		
_marshal_task_to_cs	@	dotnet.js:5
_bound_js_INTERNAL_http_wasm_fetch	@	_bound_js_INTERNAL_http_wasm_fetch:14
mono_wasm_invoke_bound_function	@	dotnet.js:5
_mono_wasm_invoke_bound_function	@	dotnet.js:6228
$aot_wrapper_System_dot_Runtime_dot_InteropServices_dot_JavaScript_System_dot_Runtime_dot_InteropServices_dot_JavaScript__Interop_sl_Runtime__InvokeJSFunction_pinvoke_void_iicl7_void_2a_void_iicl7_void_2a_	@	dotnet.wasm:0x27de96
$System_Net_Http_System_Net_Http_BrowserHttpInterop_Fetch_string_string___string___string___object___System_Runtime_InteropServices_JavaScript_JSObject_string	@	dotnet.wasm:0x269b23
$System_Net_Http_System_Net_Http_BrowserHttpHandler__CallFetchd__53_MoveNext	@	dotnet.wasm:0x26846c
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler_CallFetch_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x264a77
$System_Net_Http_System_Net_Http_BrowserHttpHandler___SendAsyncg__Impl_55_0d_MoveNext	@	dotnet.wasm:0x2658cd
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler__SendAsyncg__Impl_55_0_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x2652f1

Regression?

Yes, .NET 6 does not have this issue.

Known Workarounds

No response

Configuration

Tested on both:
main: 9567f27
release/7.0: cd2d837

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 17, 2022
@ghost
Copy link

ghost commented Oct 17, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When running the code below, the app crashes when built with an AOT profile. When running with the interpreter, or without a profile, the app runs properly.

Reproduction Steps

When running the following code using profiled AOT:

public static class Program
{
    static async Task Main(string[] args)
    {
        await Fetch();
    }

    private static async Task Fetch()
    {
        try
        {
            var client = new System.Net.Http.HttpClient()
            {
                DefaultRequestHeaders = { { "origin", "WindowsCalculator" } }
            };

            var r = await client.GetAsync(new Uri("https://cors-anywhere.herokuapp.com/https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png"));
            Console.WriteLine($"Got Response");
            var c = await r.Content.ReadAsByteArrayAsync();
            Console.WriteLine($"Got {c.Length} bytes");
        }
        catch (Exception e)
        {
            Console.WriteLine($"Failure: " + e);
        }
    }
}

Profile: aot.zip

Expected behavior

No crash, bytes are reported.

Actual behavior

Uncaught (in promise) Error: TaskT_TransitionToFinal_AlreadyCompleted
    at marshal_exception_to_js (dotnet.js:5:53508)
    at invoke_method_and_handle_exception (dotnet.js:5:76910)
    at runtimeHelpers.javaScriptExports.complete_task (dotnet.js:5:81214)
    at dotnet.js:5:39700
marshal_exception_to_js	@	dotnet.js:5
invoke_method_and_handle_exception	@	dotnet.js:5
runtimeHelpers.javaScriptExports.complete_task	@	dotnet.js:5
(anonymous)	@	dotnet.js:5
Promise.catch (async)		
_marshal_task_to_cs	@	dotnet.js:5
_bound_js_INTERNAL_http_wasm_fetch	@	_bound_js_INTERNAL_http_wasm_fetch:14
mono_wasm_invoke_bound_function	@	dotnet.js:5
_mono_wasm_invoke_bound_function	@	dotnet.js:6228
$aot_wrapper_System_dot_Runtime_dot_InteropServices_dot_JavaScript_System_dot_Runtime_dot_InteropServices_dot_JavaScript__Interop_sl_Runtime__InvokeJSFunction_pinvoke_void_iicl7_void_2a_void_iicl7_void_2a_	@	dotnet.wasm:0x27de96
$System_Net_Http_System_Net_Http_BrowserHttpInterop_Fetch_string_string___string___string___object___System_Runtime_InteropServices_JavaScript_JSObject_string	@	dotnet.wasm:0x269b23
$System_Net_Http_System_Net_Http_BrowserHttpHandler__CallFetchd__53_MoveNext	@	dotnet.wasm:0x26846c
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler_CallFetch_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x264a77
$System_Net_Http_System_Net_Http_BrowserHttpHandler___SendAsyncg__Impl_55_0d_MoveNext	@	dotnet.wasm:0x2658cd
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler__SendAsyncg__Impl_55_0_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x2652f1

Regression?

Yes, .NET 6 does not have this issue.

Known Workarounds

No response

Configuration

Tested on both:
main: 9567f27
release/7.0: cd2d837

Other information

No response

Author: jeromelaban
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@MihaZupan MihaZupan added the arch-wasm WebAssembly architecture label Oct 17, 2022
@ghost
Copy link

ghost commented Oct 17, 2022

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

Issue Details

Description

When running the code below, the app crashes when built with an AOT profile. When running with the interpreter, or without a profile, the app runs properly.

Reproduction Steps

When running the following code using profiled AOT:

public static class Program
{
    static async Task Main(string[] args)
    {
        await Fetch();
    }

    private static async Task Fetch()
    {
        try
        {
            var client = new System.Net.Http.HttpClient()
            {
                DefaultRequestHeaders = { { "origin", "WindowsCalculator" } }
            };

            var r = await client.GetAsync(new Uri("https://cors-anywhere.herokuapp.com/https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png"));
            Console.WriteLine($"Got Response");
            var c = await r.Content.ReadAsByteArrayAsync();
            Console.WriteLine($"Got {c.Length} bytes");
        }
        catch (Exception e)
        {
            Console.WriteLine($"Failure: " + e);
        }
    }
}

Profile: aot.zip
Full repro: https://github.com/jeromelaban/Wasm.Samples/tree/master/AotIssueMismatch77122

Expected behavior

No crash, bytes are reported.

Actual behavior

Uncaught (in promise) Error: TaskT_TransitionToFinal_AlreadyCompleted
    at marshal_exception_to_js (dotnet.js:5:53508)
    at invoke_method_and_handle_exception (dotnet.js:5:76910)
    at runtimeHelpers.javaScriptExports.complete_task (dotnet.js:5:81214)
    at dotnet.js:5:39700
marshal_exception_to_js	@	dotnet.js:5
invoke_method_and_handle_exception	@	dotnet.js:5
runtimeHelpers.javaScriptExports.complete_task	@	dotnet.js:5
(anonymous)	@	dotnet.js:5
Promise.catch (async)		
_marshal_task_to_cs	@	dotnet.js:5
_bound_js_INTERNAL_http_wasm_fetch	@	_bound_js_INTERNAL_http_wasm_fetch:14
mono_wasm_invoke_bound_function	@	dotnet.js:5
_mono_wasm_invoke_bound_function	@	dotnet.js:6228
$aot_wrapper_System_dot_Runtime_dot_InteropServices_dot_JavaScript_System_dot_Runtime_dot_InteropServices_dot_JavaScript__Interop_sl_Runtime__InvokeJSFunction_pinvoke_void_iicl7_void_2a_void_iicl7_void_2a_	@	dotnet.wasm:0x27de96
$System_Net_Http_System_Net_Http_BrowserHttpInterop_Fetch_string_string___string___string___object___System_Runtime_InteropServices_JavaScript_JSObject_string	@	dotnet.wasm:0x269b23
$System_Net_Http_System_Net_Http_BrowserHttpHandler__CallFetchd__53_MoveNext	@	dotnet.wasm:0x26846c
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler_CallFetch_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x264a77
$System_Net_Http_System_Net_Http_BrowserHttpHandler___SendAsyncg__Impl_55_0d_MoveNext	@	dotnet.wasm:0x2658cd
$aot_instances_aot_wrapper_gsharedvt_out_sig_void_this_	@	dotnet.wasm:0x28e984
$jit_call_cb	@	dotnet.wasm:0x20aa8
$mono_llvm_cpp_catch_exception	@	dotnet.wasm:0x2081b1
$do_jit_call	@	dotnet.wasm:0x1f6a9
$interp_exec_method	@	dotnet.wasm:0xfff5
$interp_entry	@	dotnet.wasm:0x1eaaa
$interp_entry_static_1	@	dotnet.wasm:0x21820
$aot_instances_aot_wrapper_gsharedvt_in_sig_void_bii	@	dotnet.wasm:0x296a62
$System_Net_Http_System_Net_Http_BrowserHttpHandler__SendAsyncg__Impl_55_0_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_System_Nullable_1_bool	@	dotnet.wasm:0x2652f1

Regression?

Yes, .NET 6 does not have this issue.

Known Workarounds

No response

Configuration

Tested on both:
main: 9567f27
release/7.0: cd2d837

Other information

No response

Author: jeromelaban
Assignees: -
Labels:

arch-wasm, area-System.Net.Http, untriaged

Milestone: -

@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Oct 18, 2022
@lewing lewing added this to the 8.0.0 milestone Oct 18, 2022
@lewing lewing assigned vargaz and unassigned pavelsavara Oct 18, 2022
@jeromelaban
Copy link
Contributor Author

jeromelaban commented Oct 24, 2022

@vargaz using profile filtering, I've narrowed the issue down to it being one of those AOTed:

System.Runtime.CompilerServices.*?AsyncTask.*

Still a large number of methods, but better than nothing.

@jeromelaban
Copy link
Contributor Author

Also, using net8, the error comes up as follow:

Uncaught (in promise)    at System.Threading.Tasks.TaskCompletionSource`1[[System.Runtime.InteropServices.JavaScript.JSObject, System.Runtime.InteropServices.JavaScript, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].SetException(Exception exception)
   at System.Runtime.InteropServices.JavaScript.JavaScriptExports.CompleteTask(JSMarshalerArgument* arguments_buffer)
Error: TaskT_TransitionToFinal_AlreadyCompleted
    at marshal_exception_to_js (http://localhost:63077/package_b46cfbfd8bed26910f6c35b75520b2fe0b0313b2/dotnet.js:5:39184)
    at invoke_method_and_handle_exception (http://localhost:63077/package_b46cfbfd8bed26910f6c35b75520b2fe0b0313b2/dotnet.js:5:76021)
    at runtimeHelpers.javaScriptExports.complete_task (http://localhost:63077/package_b46cfbfd8bed26910f6c35b75520b2fe0b0313b2/dotnet.js:5:80449)
    at http://localhost:63077/package_b46cfbfd8bed26910f6c35b75520b2fe0b0313b2/dotnet.js:5:48587

@vargaz
Copy link
Contributor

vargaz commented Oct 24, 2022

Would it be possible to create a testcase which uses the normal .net build ?

@jeromelaban
Copy link
Contributor Author

I'm not able to reproduce with a normal .NET build, there must be an option that's doing something differently.

The exception above being raise is hiding this exception:

RuntimeError: null function or function signature mismatch
    at System_Net_Http_System_Runtime_CompilerServices_AsyncTaskMethodBuilder_Start_System_Net_Http_HttpContent__LoadIntoBufferAsyncCored__63_System_Net_Http_HttpContent__LoadIntoBufferAsyncCored__63_ (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[20015]:0x2a305a)
    at corlib_aot_wrapper_gsharedvt_out_sig_void_this_bii (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[18891]:0x27100f)
    at jit_call_cb (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[226]:0x2105d)
    at mono_llvm_cpp_catch_exception (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[16267]:0x208847)
    at do_jit_call (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[173]:0x1fc48)
    at interp_exec_method (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[99]:0x10593)
    at interp_entry (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[152]:0x1f049)
    at interp_entry_instance_ret_2 (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[251]:0x21acd)
    at System_Net_Http_aot_wrapper_gsharedvt_in_sig_obj_this_i8cl1d_Mono_dValueTuple_601_3cint_3e_ (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[20151]:0x2a954b)
    at System_Net_Http_System_Net_Http_HttpClient___SendAsyncg__Core_83_0d_MoveNext (http://localhost:63077/package_afe58f4d046c9c3dd66af47785a06dd201d4a38c/dotnet.wasm:wasm-function[19773]:0x28947c)

@jeromelaban
Copy link
Contributor Author

jeromelaban commented Oct 24, 2022

Here's a repro with the vanilla .NET tooling. 77122-test-aot.zip

The issue only happens when HttpContent.LoadIntoBufferAsync is not AOTed (because of mono/mono#19824, which is now fixed)

@pavelsavara
Copy link
Member

cc @kotlarmilos

@kotlarmilos kotlarmilos self-assigned this Jul 30, 2024
@lewing lewing modified the milestones: 9.0.0, 10.0.0 Aug 14, 2024
@pavelsavara
Copy link
Member

is this still a problem ?

@pavelsavara pavelsavara added the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 12, 2024
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono area-System.Net.Http needs-author-action An issue or pull request that requires more info or actions from the author.
Projects
None yet
Development

No branches or pull requests

6 participants