Wasm debugging from VS Code ends at once when WasmEnableThreads is on, even with no threads started
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C#
- スター
- 18.4k
- フォーク
- 5.8k
- 平均マージ
- 2日 19時間
- マージ済み PR(30日)
- 590
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/runtime のほかの issue
-
area-Setup untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
dotnet/runtime#137376 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area-System.Memory untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
dotnet/runtime#137334 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
ImmutableSortedSet<T>.Builder: enumerating through IEnumerable<T> doesn't throw on modification and can return wrong items対応中かも @aw0lid が 3 日前に担当しました。 オープンarea-System.Collections
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#137167 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by design対応中かも @alaricd が 7 日前に担当しました。 オープンarea-System.Transactions untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/runtime#137040 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the file対応中かも @makazeu が 7 日前に担当しました。 オープンarea-Extensions-FileSystem
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#136989 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug emitter:client:csharp
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microsoft/typespec#12572 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
newrelic/newrelic-dotnet-agent#3949 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area-networking
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/aspnetcore#70545 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 87/100
メンテナーはふだん 1 日以内に返信