| index 459bdf16c..ca1790c52 100644 |
| --- a/internal/demobuild/transfer_test.go |
| +++ b/internal/demobuild/transfer_test.go |
| @@ -225,3 +225,77 @@ func TestDemoBuildOutputTransferPeak(t *testing.T) { |
| t.Logf("GOMEMLIMIT=%q GOGC=%q: peak HeapAlloc=%d MiB, peak Sys-HeapReleased=%d MiB, maxrss before=%d MiB after=%d MiB (delta %d MiB)", |
| os.Getenv("GOMEMLIMIT"), os.Getenv("GOGC"), peakHeap.Load()>>20, peakSys.Load()>>20, before>>20, after>>20, (after-before)>>20) |
| } |
| + |
| +// shstrndxPanicELF is an AArch64 executable header whose section table |
| +// makes debug/elf (Go 1.26.10, file.go:596) index past its sections: e_shnum |
| +// 0 and e_shstrndx SHN_XINDEX send the parser to section 0, whose sh_size |
| +// (0xff00 sections) and sh_link (string table 0xffff) it accepts without |
| +// checking one against the other. The table itself is zeros. |
| +func shstrndxPanicELF() []byte { |
| + const shoff, sections = 4096, 0xff00 |
| + b := arm64ELFOfSize(shoff + sections*64) |
| + binary.LittleEndian.PutUint64(b[40:], shoff) // e_shoff |
| + binary.LittleEndian.PutUint16(b[58:], 64) // e_shentsize |
| + binary.LittleEndian.PutUint16(b[60:], 0) // e_shnum: see section 0 |
| + binary.LittleEndian.PutUint16(b[62:], 0xffff) // e_shstrndx: SHN_XINDEX |
| + binary.LittleEndian.PutUint64(b[shoff+32:], sections) |
| + binary.LittleEndian.PutUint32(b[shoff+40:], 0xffff) |
| + return b |
| +} |
| + |
| +// panicked runs f and returns what it panicked with, or nil. |
| +func panicked(f func()) (p any) { |
| + defer func() { p = recover() }() |
| + f() |
| + return nil |
| +} |
| + |
| +// A panic while root validates an output (here a real one, inside |
| +// debug/elf, from the build's own bytes) unwinds through Run. net/http |
| +// recovers it and the service lives on, so the turn must come back with |
| +// the unwinding or every later build waits out its deadline. |
| +func TestDemoBuildOutputTransferValidationPanicReleases(t *testing.T) { |
| + ctx, dir := finishedBuild(t, shstrndxPanicELF()) |
| + p := panicked(func() { |
| + out, err := Run(ctx, dir, testLock(t)) |
| + out.Release() |
| + t.Logf("no panic: err=%v", err) |
| + }) |
| + if p == nil { |
| + t.Fatal("the fixture no longer panics debug/elf; this test needs another panic source") |
| + } |
| + if !transferFree(t) { |
| + t.Fatalf("a validation panic (%v) kept the output turn", p) |
| + } |
| +} |
| + |
| +// A panic in Worker.Build's scratch cleanup, after Run handed it an output |
| +// holding the turn, must give the turn back, and a later output can take |
| +// it. The worker is poisoned: its scratch was not proven removed. |
| +func TestDemoBuildOutputTransferCleanupPanicReleases(t *testing.T) { |
| + w, j, key, src := workerFixture(t) |
| + bctx, bdir := finishedBuild(t, arm64ELF()) |
| + i := bctx.Value(runContextKey{}).(*runInvocation) |
| + w.run = func(ctx context.Context, _ string, lock Lock) (BuildOutput, error) { |
| + return Run(context.WithValue(ctx, runContextKey{}, i), bdir, lock) |
| + } |
| + w.prepare = func(context.Context, string, Source) (func() error, error) { |
| + return func() error { panic("cleanup") }, nil |
| + } |
| + wire, err := SignJob(key, j) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if p := panicked(func() { w.Build(t.Context(), wire, bytes.NewReader(src)) }); p != "cleanup" { |
| + t.Fatalf("panic=%v", p) |
| + } |
| + if !transferFree(t) { |
| + t.Fatal("a cleanup panic kept the output turn") |
| + } |
| + w.mu.Lock() |
| + poisoned := w.poisoned |
| + w.mu.Unlock() |
| + if !poisoned { |
| + t.Fatal("cleanup panicked and the worker was not poisoned") |
| + } |
| +} |