Change information
Commit message:
gopls: two mitigations for "surplus bytes" crash
In go.dev/issue/80166 a "surplus bytes" error was observed during
frob decoding. This "cannot happen" because Encode and Decode
are strictly dual, and the design of the cache means that
we do not attempt to decode a file with the wrong checksum,
so hardware faults or file system corruption is eliminated as
a cause.
This CL adds two defensive measures to try to resolve the mystery:
1) frob encoding asserts that the number of map iterations
matches the length, in case the map was somehow concurrently
mutated. (Better to crash than write a corrupt cache entry.)
2) during filecache creation, we record the complete SHA digest
of th executable, and check it on subsequent startups that
hit an existing directory, in case we have a case of the
birthday paradox (though with 32 bits this is exceeedingly
unlikely).
Also, simplify using sync.OnceValues.
For golang/go#80166
Change-Id: I26625a806b10087070a4f4b67f78bd0156b48357
Files:
- M gopls/internal/filecache/filecache.go
- M gopls/internal/util/frob/frob.go
Change size: M
Delta: 2 files changed, 56 insertions(+), 48 deletions(-)
Branch: refs/heads/master