跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

0009-start-channels-buffered.patch

34 行 · 1.3 KB历史下载
1Subject: [PATCH] instance: do not leave goroutines blocked after Start returns
2
3StartWithPaths races two goroutines (the hostagent's events and its exit)
4on unbuffered channels and returns on the first. The loser blocks on its
5send for as long as the program lives: one goroutine per start in a program
6that outlives the call (limactl exits, so it does not show there). The
7channels hold one value, so the sends complete; the exit goroutine also
8finishes its Wait, which reaps the hostagent when it ends.
9
10No test: StartWithPaths starts a hostagent, which Lima's unit tests do not.
11
12---
13diff --git a/pkg/instance/start.go b/pkg/instance/start.go
14index 0c70232a..489df5f9 100644
15--- a/pkg/instance/start.go
16+++ b/pkg/instance/start.go
17@@ -319,12 +319,15 @@ func StartWithPaths(ctx context.Context, inst *limatype.Instance, launchHostAgen
18 return err
19 }
20
21- watchErrCh := make(chan error)
22+ // Buffered: the goroutine that loses the race below must not block on its
23+ // send for as long as the program lives (it would, once StartWithPaths
24+ // has returned).
25+ watchErrCh := make(chan error, 1)
26 go func() {
27 watchErrCh <- watchHostAgentEvents(ctx, inst, haStdoutPath, haStderrPath, begin, showProgress)
28 close(watchErrCh)
29 }()
30- waitErrCh := make(chan error)
31+ waitErrCh := make(chan error, 1)
32 if haCmd != nil {
33 go func() {
34 waitErrCh <- haCmd.Wait()