However, we also guard initialization with a sync.Once. As has been observed in #43554, it's possible to lose this race to awaitInitialized, such that we run initialization on the snapshot background context, which can be canceled.
As a result, we can clone a snapshot with incomplete metadata. This causes problems for any invalidation logic trying to preserve metadata, such as only invalidating metadata on go.mod saves. Additionally, this was difficult to debug: it would be nice to have a guarantee that we have a linear history of metadata in our snapshots.
After discussing, we think this is a relatively low priority since the current logic should only result in rare and transient breakages.
Jumping to definition in a regtest can indirectly lead to a didOpen
call, so the awaits added to TestUseGoplsMod to synchronize metadata
were ineffectual. On Android, this can lead to the race described in
But in any case, all this bookkeeping of notifications is fragile. Avoid
it entirely by having the fake editor keep track of notification
statistics. In the future, we should use this to clean up many existing
Run-TryBot: Robert Findley <firstname.lastname@example.org>
gopls-CI: kokoro <email@example.com>
Trust: Robert Findley <firstname.lastname@example.org>
TryBot-Result: Go Bot <email@example.com>
Reviewed-by: Rebecca Stambler <firstname.lastname@example.org>