Wasm debugging from VS Code ends at once when WasmEnableThreads is on, even with no threads started
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reading the BrowserDebugProxy code paths described in the issue, especially ClearState and the handling of commands sent to workers before their runtimes start. The issue identifies five worker debugging failures, with the first two ending the session; use the attached workaround's README and Program.cs as pointers to the fixes. Done means the repro reaches its breakpoint with WasmEnableThreads enabled.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Related to #81282 (support debugging multi-threaded apps).
Turning on <WasmEnableThreads>true</WasmEnableThreads> makes a .NET browser app impossible to debug from VS Code.
The browser opens, then closes straight away, the debugging session ends, and no breakpoint is hit. The app needn't
start any threads of its own: enabling threads is enough. The same app with threads off debugs normally.
The session goes through the wasm debug proxy (BrowserDebugProxy, which dotnet run's dev server starts at
/_framework/debug/ws-proxy), as the C# extension's blazorwasm launch type sets up.
A workaround is attached under Known Workarounds (dotnet-debug-proxy-workaround.zip). It hosts the SDK's own
BrowserDebugProxy.dll with fixes for five problems the proxy has with Web Workers:
- Resuming a worker ends the session, and a breakpoint hit on a worker isn't shown.
- Commands sent through a new worker, before its runtime has started, end the session.
- A worker's C# frames have no source.
- Readying a worker's context clears every breakpoint, the page's included.
- A thread that never returns to JavaScript can't be stopped on.
The first two end the session, which is what this repro shows. With the workaround, the repro debugs normally. Each
problem's cause is under Other information.
Reproduction Steps
Four files in one folder.
ThreadsRepro.csproj:
<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<WasmEnableThreads>true</WasmEnableThreads>
</PropertyGroup>
</Project>
Program.cs:
using System;
using System.Threading.Tasks;
// Starts no threads of its own. Main calls Tick once a second.
for (int ticks = 1; ; ticks++)
{
Console.WriteLine($"main, tick {ticks}: {Tick(10)}");
await Task.Delay(1000);
}
static int Tick(int count)
{
int total = 0;
for (int i = 0; i < count; i++)
{
total += i;
}
return total;
}
wwwroot/index.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>threads repro</title>
</head>
<body>
<p>The app's output is in the browser's console.</p>
<script type="module">
import { dotnet } from './_framework/dotnet.js';
await dotnet.run();
</script>
</body>
</html>
Properties/launchSettings.json:
{
"profiles": {
"ThreadsRepro": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://127.0.0.1:5000"
}
}
}
-
Install the .NET 10 SDK, its
wasm-toolsworkload, and VS Code's C# extension. -
Open the folder in VS Code, and add this launch configuration (
.vscode/launch.json):{ "type": "blazorwasm", "request": "launch", "name": "repro", "cwd": "${workspaceFolder}", "url": "http://127.0.0.1:5000/", "browser": "chrome" } -
Set a breakpoint on line 13 of
Program.cs(int total = 0;). -
Start debugging with repro.
Expected behavior
The breakpoint is hit once a second.
Actual behavior
Chrome opens, then closes, and the debugging session ends. The breakpoint isn't hit.
With <WasmEnableThreads>false</WasmEnableThreads>, and nothing else changed, the breakpoint is hit.
Regression?
No
Known Workarounds
The attached dotnet-debug-proxy-workaround.zip is a small ASP.NET Core app that hosts the SDK's own
BrowserDebugProxy.dll, patched by reflection, with a fix for each of the five problems in the description. Its
README.md and the header of its Program.cs describe each fix. It's released into the public domain (the Unlicense,
LICENSE), to use, modify and share as you wish.
To use it with the repro:
-
Run the app with
dotnet runin the repro's folder. -
Run the workaround with
dotnet runin its folder. It listens athttp://127.0.0.1:8791. -
Debug with this configuration in place of repro:
{ "type": "chrome", "request": "launch", "name": "workaround", "url": "http://127.0.0.1:5000/", "inspectUri": "ws://127.0.0.1:8791/?browser={browserInspectUri}", "webRoot": "${workspaceFolder}", "timeout": 60000 }
The breakpoint is then hit.
dotnet-debug-proxy-workaround.zip
Configuration
| Component | Version |
|---|---|
| .NET SDK | 10.0.401 |
WebAssembly SDK (WasmAppHost) |
10.0.11 |
| VS Code | 1.145.2 |
| C# extension | 2.160.4 |
| JavaScript Debugger (js-debug) | 1.140.0 |
| Chrome | 156.0.8078.80 |
| OS | Windows 11 Pro 10.0.26200, x64 |
Other information
With threads on, .NET runs on Web Workers, even when the app starts no threads: its worker pool, and its own threads.
We found these five problems debugging a larger multithreaded app, by reading the proxy's source and its log.
Two of them end the session, and both happen as soon as a threaded app starts, as each new worker attaches to the
debugger. The debugger resumes the new worker, and the proxy throws in ClearState (1). The debugger sends the new
worker its settings and breakpoints, which the proxy sends on through a worker whose runtime hasn't started yet, and
they fail (2). Either failure ends the session. The other three don't end it, but hide stops, frames or breakpoints on
workers, once a session runs.
- A breakpoint hit on a worker isn't shown, and resuming a worker ends the session. The proxy makes an
ExecutionContextfor each worker without its page's debugger data (SdbAgent, and the loaded symbols). It copies
them in only when a pause has anasyncStackTraceId, which Chrome sends only when the worker's code was called from
another target. Without them,SendCallStackthrows when a breakpoint is hit on the worker, and the proxy resumes
the worker without showing the stop.ClearStatethrows when the debugger resumes a worker, which ends the
debugging session. - Commands sent through a new worker end the session. Once a worker's context is ready, the proxy sends its
commands (setPauseOnExceptions, breakpoints) through that worker. They fail while a new worker is paused before
its runtime has started, and the failure ends the session. - A worker's C# frames have no source. The proxy announces the C# sources (
Debugger.scriptParsed) only on the
page's session. The debugger looks for a frame's source among its own thread's scripts, so it can't show the
worker's C# frames. - Readying a worker's context clears every breakpoint. For a context that isn't ready (
RuntimeReady, as for
getPossibleBreakpoints, which the debugger sends after each pause), the proxy first clears every breakpoint. The
runtime's debugger agent serves every thread, so this clears the page's breakpoints too. - A thread that never returns to JavaScript can't be stopped on. The proxy reads a worker's debugger commands
throughgetDotnetRuntime(0). .NET's script registers the runtime on a worker only as the last step of its start
(preInitWorker), after awaits. A thread started as its worker finishes loading runs first. If it then never
returns to JavaScript, as a thread running a blocking loop doesn't, those awaits never finish. Every breakpoint hit
on it then throws in the proxy (Cannot read properties of undefined (reading 'INTERNAL')), and the proxy drops it.
- Lingua principale
- C#
- Stelle
- 18.4k
- Fork
- 5.8k
- Merge medio
- 2g 19h
- PR unite (30g)
- 590
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dotnet/runtime
-
area-Setup untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
dotnet/runtime#137376 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-System.Memory untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
dotnet/runtime#137334 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
ImmutableSortedSet<T>.Builder: enumerating through IEnumerable<T> doesn't throw on modification and can return wrong itemsForse già presa @aw0lid l’ha presa 3 giorni fa. Apertaarea-System.Collections
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/runtime#137167 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designForse già presa @alaricd l’ha presa 7 giorni fa. Apertaarea-System.Transactions untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dotnet/runtime#137040 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the fileForse già presa @makazeu l’ha presa 7 giorni fa. Apertaarea-Extensions-FileSystem
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/runtime#136989 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di dotnet/runtime
Issue simili
-
bug emitter:client:csharp
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
microsoft/typespec#12572 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
needs-area-label
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-networking
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/aspnetcore#70545 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno