Wasm debugging from VS Code ends at once when WasmEnableThreads is on, even with no threads started
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 18.4k
- Fork
- 5.8k
- Merge trung bình
- 2 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 590
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/runtime
-
area-Setup untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dotnet/runtime#137376 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-System.Memory untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dotnet/runtime#137334 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ImmutableSortedSet<T>.Builder: enumerating through IEnumerable<T> doesn't throw on modification and can return wrong itemsCó thể đã có người làm @aw0lid đã nhận 3 ngày trước. Đang mởarea-System.Collections
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/runtime#137167 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designCó thể đã có người làm @alaricd đã nhận 7 ngày trước. Đang mởarea-System.Transactions untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/runtime#137040 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the fileCó thể đã có người làm @makazeu đã nhận 7 ngày trước. Đang mởarea-Extensions-FileSystem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/runtime#136989 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/runtime
Issue tương tự
-
bug emitter:client:csharp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/typespec#12572 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-networking
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/aspnetcore#70545 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày