Skip to content

[browser][MT] dedicated io thread - #99422

Merged
pavelsavara merged 9 commits into
dotnet:mainfrom
pavelsavara:browser_mt_io_thread
Mar 14, 2024
Merged

[browser][MT] dedicated io thread#99422
pavelsavara merged 9 commits into
dotnet:mainfrom
pavelsavara:browser_mt_io_thread

Conversation

@pavelsavara

@pavelsavarapavelsavara commented Mar 7, 2024

Copy link
Copy Markdown
Member
  • dispatch Task resolve/reject to dedicated managed I/O thread and continuations to managed ThreadPool
  • allow blocking .Wait on deputy thread in async methods, async JSExport, C# Main()
  • keep throwing PNSE inside synchronous JSExport or callback

changes

  • new JSThreadBlockingMode.AllowBlockingWaitInAsyncCode, make it default
  • ToManaged(Task) creates Task with TaskCreationOptions.RunContinuationsAsynchronously
  • mono_wasm_create_io_thread, mono_wasm_register_io_thread, mono_wasm_start_io_thread_async
  • dispatch Promise/Task resolution to I/O Thread
  • dispatch release_js_owned_object_by_gc_handle to I/O thread from UI thread
  • call BeforeSyncJSExport and AfterSyncJSExport also on JSWebWorker (same thread)
  • fix ConfigureAwait(true) in HTTP client
  • add mono_wasm_print_thread_dump to INTERNAL

tests

  • WaitDoesNotAssertInAsyncCode <-- this is why we do this!
  • WaitAssertsOnSyncCallback
  • WaitAssertsOnSyncJSExport
  • _XUnitBackgroundExec not default, we don't need it anymore because blocking is fine!
  • delete System.Runtime.InteropServices.JavaScript.BackgroundExec.Tests

new active issues

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

we have deadlock in

 public static void InitializationWithUriOnNonAsyncReaderThrows()
{
Assert.Throws<System.Net.Http.HttpRequestException>(() => XmlReader.Create("http://test.test/test.html", new XmlReaderSettings() { Async = false }));
}

This is exactly the scenario that this PR should solve. It's synchronous Wait on fetch.
When I added bunch of Console.WriteLine in the code of XmlDownloadManager.GetStream it fixed itself.
I don't know why yet.

returnGetNonFileStreamAsync(uri,credentials,proxy).GetAwaiter().GetResult();

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@marafmaraf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm missing change in dotnet.d.ts. Most of the comments are nits

Comment threadeng/testing/tests.browser.targets
Comment threadsrc/mono/browser/runtime/globals.ts
Comment threadsrc/mono/browser/runtime/pthreads/io-thread.ts
Comment threadsrc/mono/browser/runtime/multi-threading.md Outdated
Comment threadsrc/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
pavelsavaraand others added 7 commits March 14, 2024 13:24
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
…stem/Runtime/InteropServices/JavaScript/Marshaling/JSMarshalerArgument.Task.cs
Co-authored-by: Marek Fišera <mara@neptuo.com>
Co-authored-by: Marek Fišera <mara@neptuo.com>
@pavelsavara
pavelsavara merged commit 411f7e6 into dotnet:mainMar 14, 2024
@pavelsavara
pavelsavara deleted the browser_mt_io_thread branch March 14, 2024 15:43
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 14, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-VM-threading-monoos-browserBrowser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@pavelsavara@maraf