Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions desktop/internal/workbench/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,14 @@ type App struct {
// savedBackground is the window background last stored (window_background.go).
savedBackground gfx.Color
focus focusTarget
// debugHostedPort and debugInitializeWindow replace, in tests, asking the
// language server for a debug port and Core's initialize deadline. Production
// leaves both zero.
debugHostedPort func(ctx context.Context, p *project, adapter debugAdapter) (int, error)
debugInitializeWindow time.Duration
kernel Kernel
store *store.Store
// debugHostedPort, debugInitializeWindow, and debugInitializeTrigger replace,
// in tests, asking the language server for a debug port and Core's initialize
// deadline. Production leaves all three zero.
debugHostedPort func(ctx context.Context, p *project, adapter debugAdapter) (int, error)
debugInitializeWindow time.Duration
debugInitializeTrigger <-chan struct{}
kernel Kernel
store *store.Store
// startupPath is the project folder the window opens once it exists (Options.OpenPath).
startupPath string
startupFile string
Expand Down
54 changes: 46 additions & 8 deletions desktop/internal/workbench/debug_announced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestDebugAnnouncedAdapterRunner(t *testing.T) {
type announcedWatch struct {
listener net.Listener
accepted chan net.Conn
conn net.Conn
}

// announcedWorkspace is the fixture workspace for one mode, and the watch the
Expand All @@ -150,6 +151,9 @@ func announcedWorkspace(t *testing.T, mode string) (root, source string, watch *
watch = &announcedWatch{listener: listener, accepted: make(chan net.Conn, 1)}
t.Cleanup(func() {
_ = listener.Close()
if watch.conn != nil {
_ = watch.conn.Close()
}
select {
case conn := <-watch.accepted:
if conn != nil {
Expand All @@ -176,20 +180,33 @@ func announcedWorkspace(t *testing.T, mode string) (root, source string, watch *
return root, source, watch
}

// ended waits for the fixture process to end and returns what it reported
// before it did.
func (w *announcedWatch) ended(t *testing.T, limit time.Duration) string {
// awaitConnected waits for the fixture process to connect to the watch so tests
// can synchronize deterministically with the running child before triggering
// timeouts.
func (w *announcedWatch) awaitConnected(t *testing.T, limit time.Duration) {
t.Helper()
deadline := time.Now().Add(limit)
var conn net.Conn
if w.conn != nil {
return
}
select {
case conn = <-w.accepted:
case conn := <-w.accepted:
if conn == nil {
t.Fatal("the adapter watch listener stopped before accepting the connection")
}
w.conn = conn
case <-time.After(limit):
t.Fatal("the adapter process never connected to the watch")
}
}

// ended waits for the fixture process to end and returns what it reported
// before it did.
func (w *announcedWatch) ended(t *testing.T, limit time.Duration) string {
t.Helper()
deadline := time.Now().Add(limit)
w.awaitConnected(t, limit)
conn := w.conn
w.conn = nil
defer conn.Close()
if err := conn.SetReadDeadline(deadline); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -292,15 +309,36 @@ func TestDebugAnnouncedRemoteEndpointFailsAndStopsTheProcess(t *testing.T) {
func TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut(t *testing.T) {
h := debugPluginHarness(t, "dev.lithe.test.debug-announced", debugAnnouncedManifest, true)
root, _, watch := announcedWorkspace(t, "silent")
// A race-instrumented child can take over a second to reach its watch.
h.app.debugInitializeWindow = 3 * time.Second
// Control the initialize timeout deterministically so child startup never
// races the timeout clock.
trigger := make(chan struct{})
t.Cleanup(func() {
select {
case <-trigger:
default:
close(trigger)
}
})
h.app.debugInitializeTrigger = trigger
p := openHostedPanel(t, h, root)
h.clickNamed(h.app.text.Debug.Start)
session := p.debug.activeSession()
if session == nil {
t.Fatal("the announced adapter never entered its startup session")
}
watch.awaitConnected(t, 20*time.Second)
close(trigger)
awaitStateWithin(t, h, 20*time.Second, "the timeout", func() bool { return p.debug.failure != "" })
if p.debug.failure != h.app.text.Debug.TimedOut || p.debug.activeSession() != nil {
t.Fatalf("failure = %q, want the timeout message", p.debug.failure)
}
watch.ended(t, 20*time.Second)
awaitDebugSessionDone(t, session)
select {
case <-session.cleanupDone:
case <-time.After(debugAdapterExitWait):
t.Fatal("the timed-out debug session did not finish cleanup before the deadline")
}
}

// announcementRecorder is a reader whose Core answer is a fixed rule: a line
Expand Down
16 changes: 14 additions & 2 deletions desktop/internal/workbench/debug_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func (a *App) beginDebug(p *project, start debugStart) {
// Core owns the length of the window (the transport policy's initialization
// deadline); the host only runs the clock.
func (a *App) watchDebugInitialize(p *project, session *debugSession, window time.Duration) {
timer := time.AfterFunc(window, func() {
timeout := func() {
// The window is the start's deadline: an adapter start that has no result by now
// timed out. A start that already ended keeps its result.
a.recordDebugStart(session.ctx, session, core.StageTimeout, context.DeadlineExceeded)
Expand All @@ -666,7 +666,19 @@ func (a *App) watchDebugInitialize(p *project, session *debugSession, window tim
a.finishDebugError(p, session, errors.New(a.text.Debug.TimedOut))
}
})
})
}
if a.debugInitializeTrigger != nil {
trigger := a.debugInitializeTrigger
go func() {
select {
case <-trigger:
timeout()
case <-session.ctx.Done():
}
}()
return
}
timer := time.AfterFunc(window, timeout)
// The timer must not outlive the session: Stop and shutdown cancel its context.
context.AfterFunc(session.ctx, func() { timer.Stop() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
]
},
"owner": "Debug",
"verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。",
"notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。",
"verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。 tcpAnnounced 的无应答初始化超时回归执行 TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut:测试先通过 watch.awaitConnected 确认子进程已启动并建立观察连接,再由 debugInitializeTrigger 确定性触发初始化超时;断言宿主报告 TimedOut、会话释放,并通过 watch.ended、startupDone/exitObserved 与 cleanupDone 确认子进程及清理全部有界完成。继续保留其他用例检查确实有 TCP 连接后发送 disconnect 的流程;macOS/Windows 原生验收仍待完成。",
"notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。 #1962:此前超时测试使用固定定时器(300ms / 3s)与子进程启动和连接 watch 竞争;改为测试在确认子进程连上 watch 后通过 debugInitializeTrigger 确定性触发 watchDebugInitialize 超时,并验证进程退出与清理完成,不改生产调试超时或协议。",
"legacy": {
"revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",
"macos": {
Expand Down
Loading