Make reading a header's opcodes safe for concurrent readers

indexOf wrote the node's remembered index even when it was right, so
Header.Get raced when a document was read from several goroutines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 19:15:55 +00:00
co-authored by Claude Sonnet 5.5
parent 158661eefe
commit e08f3a5d0b
2 changed files with 29 additions and 1 deletions
+4 -1
View File
@@ -24,7 +24,10 @@ func (h *Header) Name() string { return h.Node.Name }
// so the search starts there and goes outwards.
func (f *File) indexOf(n *Node) int {
at := func(i int) bool { return i >= 0 && i < len(f.Nodes) && f.Nodes[i] == n }
for d := 0; ; d++ {
if at(n.idx) {
return n.idx
}
for d := 1; ; d++ {
if at(n.idx + d) {
n.idx += d
return n.idx