From 9e0086bc9208d21893924c777ef3299d8a788820 Mon Sep 17 00:00:00 2001 From: Mus Date: Tue, 17 Nov 2026 20:05:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=A3=80?= =?UTF-8?q?=E6=B5=8B/=E4=B8=8B=E8=BD=BD=E7=9A=84=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E4=B8=8D=E5=86=8D=E5=B9=B6=E5=8F=91=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=EF=BC=8Cdone=20=E4=B8=8D=E4=BC=9A=E5=80=92=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runUnits 里每个 worker 各自 notify 进度事件,而 done 是加锁累加的:两个 worker 同时收尾时, done=2 的事件可能先于 done=1 出去,界面进度条会往回跳;回调并发还让测试里的收集函数在 append 上打架,TestRemoteProgressReportsDoneNotUploaded 偶发「只覆盖了 5 处引用」。 改成在累加 done 的同一把锁里发事件,顺带把 emit 的并发约定写进注释。 --- internal/conv/remote.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/conv/remote.go b/internal/conv/remote.go index b1eed1a..eb28a93 100644 --- a/internal/conv/remote.go +++ b/internal/conv/remote.go @@ -159,7 +159,9 @@ func (r *Runner) runUnits(ctx context.Context, id string, docDir string, groups mu.Lock() done++ progress := done - mu.Unlock() + // 进度事件在锁里发:done 保证单调递增,回调也不会被多个 worker 同时调用。 + // 下游(app.Batcher、测试里的收集函数)都按「同一个文件的事件是顺序来的」写, + // 一旦并发进来,done 会倒退、Items 增量会在并发追加里丢掉。 r.notify(Event{ Type: EventFileProgress, ID: id, @@ -167,6 +169,7 @@ func (r *Runner) runUnits(ctx context.Context, id string, docDir string, groups Total: total, Items: patches, }) + mu.Unlock() } }() } From 81010d4187a7fd635ce038aaf968b75d8ea95589 Mon Sep 17 00:00:00 2001 From: Mus Date: Tue, 17 Nov 2026 20:06:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E6=A1=A3=EF=BC=9A=E5=86=99?= =?UTF-8?q?=E6=B8=85=20Emit=20=E5=9B=9E=E8=B0=83=E7=9A=84=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E7=BA=A6=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/conv/runner.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/conv/runner.go b/internal/conv/runner.go index cd65c9a..ca0d4bc 100644 --- a/internal/conv/runner.go +++ b/internal/conv/runner.go @@ -20,6 +20,9 @@ import ( ) // Emit 是事件回调,可以为 nil(CLI 模式)。 +// Emit 是事件出口。它可能被多个 goroutine 同时调用(多个文件并行转换,日志事件也是随时发的), +// 实现方必须自己保证并发安全;同一个文件的进度事件由 runner 串行发出,done 单调递增、 +// Items 增量按顺序到达。 type Emit func(Event) type cacheEntry struct {