Repository: go
Issue: x/tools/gopls: sigpanic in persistent.(*mapNode).forEach
Labels: NeedsInvestigation,gopls,Tools,gopls/telemetry-wins,BugReport

```
#!stacks
"runtime.sigpanic" && "persistent.(*mapNode).forEach:+1"
```
Issue created by [stacks](https://pkg.go.dev/golang.org/x/tools/gopls/internal/telemetry/cmd/stacks).

This stack looks wrong, perhaps another example of the off-by-one problems in the traceback?
(Is it possible that somehow the tree has become a cyclic graph and what we are seeing is a stack overflow? The line number supports that, but I would expect the failure in that case to occur in `runtime.morestack_noctxt`.)

```go
func (node *mapNode) forEach(f func(key, value any)) {
	if node == nil {   // <--- sigpanic
		return
	}
	node.left.forEach(f)
	f(node.key, node.value.value)
	node.right.forEach(f)
}
```

This stack `dVh6PA` was [reported by telemetry](https://storage.googleapis.com/prod-telemetry-merged/2024-12-31.json):

- `crash/crash`
- [`runtime.throw:+9`](https://cs.opensource.google/go/go/+/go1.23.2:src/runtime/panic.go;l=1067)
- [`runtime.sigpanic:+33`](https://cs.opensource.google/go/go/+/go1.23.2:src/runtime/signal_unix.go;l=914)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+1`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=169)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+6`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=174)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+6`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=174)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+6`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=174)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+6`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=174)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+6`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=174)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
- [`golang.org/x/tools/gopls/internal/util/persistent.(*mapNode).forEach:+4`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0:gopls/internal/util/persistent/map.go;l=172)
```
golang.org/x/tools/gopls@v0.17.0 go1.23.2 linux/amd64 vscode (1)
```