]> Cypherpunks repositories - gostls13.git/commitdiff
internal/trace: emit final sync event for generation in Go 1.26+
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 15 Aug 2025 23:30:08 +0000 (23:30 +0000)
committerGopher Robot <gobot@golang.org>
Sat, 16 Aug 2025 01:10:28 +0000 (18:10 -0700)
CL 693398 returned the error from reading a generation immediately, but
this is wrong -- a Sync event must be emitted to indicate the end of the
trace before reporting the error. This caused TestCrashWhileTracing
to fail because that test has a high likelihood of producing a truncated
trace, and it expects at least 2 Sync events. The truncated trace error
would be reported before the second Sync event, which is incorrect.

Fixes #75045.

Change-Id: Ia71592c4ec56a544afc85cdb7b575e143f80e048
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/696436
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/trace/reader.go

index 5a094277fb5de64fc3e6c700819e0dade5d1e88f..bb9cc280f5c981921165aa96001dc62f47444559 100644 (file)
@@ -31,6 +31,7 @@ type Reader struct {
        cpuSamples []cpuSample
        order      ordering
        syncs      int
+       readGenErr error
        done       bool
 
        // Spill state.
@@ -153,9 +154,18 @@ func (r *Reader) ReadEvent() (e Event, err error) {
                if r.version < version.Go126 {
                        return r.nextGenWithSpill()
                }
+               if r.readGenErr != nil {
+                       return Event{}, r.readGenErr
+               }
                gen, err := readGeneration(r.r, r.version)
                if err != nil {
-                       return Event{}, err
+                       // Before returning an error, emit the sync event
+                       // for the current generation and queue up the error
+                       // for the next call.
+                       r.readGenErr = err
+                       r.gen = nil
+                       r.syncs++
+                       return syncEvent(nil, r.lastTs, r.syncs), nil
                }
                return r.installGen(gen)
        }