Commit c7335ae
authored
Don't crash reading the config of a subrepo with no remote tree (#3577)
Building a Rust plugin against a repo with ~100 crate subrepos, we hit
an intermittent segfault under remote execution whenever Please read a
subrepo's config:
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18]
please/src/remote/fs.New({...}, 0x0, {...}) fs.go:67
please/src/remote.(*Client).SubrepoFS(...) remote.go:330
please/src/core.(*Subrepo).FS.func1() subrepo.go:58
please/src/core.readSubrepoConfig(...) subrepo.go:119
```
Note the literal `0x0` argument. `SubrepoFS` looks the subrepo's output
tree up by label and passes whatever it finds straight to
`remotefs.New`:
```go
tree := c.subrepoTrees[target.Label]
return remotefs.New(c.remoteFSClient, tree, root)
```
`subrepoTrees` is only ever populated in one place (`utils.go`, when a
target's outputs are set from a *remote* build), so a subrepo that was
built locally, served from the cache, or not built yet has no entry, and
`tree` is nil. `New` then does `append(tree.Children, tree.Root)` and
dies. `readSubrepoConfig` calls `Subrepo.FS()` unconditionally — it has
to, in order to look for `.plzconfig` — so any repo whose subrepo
targets can come from cache rather than a fresh remote build can hit
this.
That matches what we saw: it was sensitive to cache state and flipped
between otherwise identical runs.
This makes a nil tree (or one with no root) produce an empty filesystem,
so the config lookup reports "does not exist" and parsing continues —
which is already the handling for a subrepo that has no `.plzconfig`.
The added test panics at the same `addr=0x18` without the change and
passes with it.
`plz test //src/remote/...` is green.1 parent 9ee7615 commit c7335ae
2 files changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
67 | 76 | | |
68 | 77 | | |
69 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
0 commit comments