Repository: go
Issue: x/tools/gopls: regtest flakes due to hanging go commands
Labels: gopls,Tools

```
#!watchflakes
post <- goos != "netbsd" && (pkg ~ `^golang.org/x/tools/gopls` || (repo == "tools" && pkg == "")) && 
        (`detected hanging go command` || log ~ `detected hanging go command` || `DETECTED A HANGING GO COMMAND` || log ~ `DETECTED A HANGING GO COMMAND`)
```

> greplogs --dashboard -md -l -e 'runCmdContext' --since=2022-07-14

<details>

[2022-08-15T17:42:12-987de34-1f833e4/darwin-amd64-12_0](https://build.golang.org/log/00046e0b005c7660d676a3a415561950048f756a)
[2022-08-14T00:06:23-35f806b-59865f1/netbsd-amd64-9_0](https://build.golang.org/log/cac6093c9a1e29b020d1a0076f0b67e262a134c5)
[2022-08-12T20:40:05-bebd890-2f6783c/netbsd-386-9_0](https://build.golang.org/log/3680daecab8adb2905484af9298a4239b3812f6a)
[2022-08-12T18:15:28-bebd890-b6f87b0/netbsd-amd64-9_0](https://build.golang.org/log/c2900e262adb237ea981093befa87ec35faa804b)
[2022-08-12T12:39:26-88d981e-f67c766/netbsd-amd64-9_0](https://build.golang.org/log/d22326763f8cbedb39bb3c17f3e66e57efa453df)
[2022-08-12T00:04:29-c4ec74a-a5cd894/netbsd-386-9_0](https://build.golang.org/log/eec2b475f968a73f4f17745f72013ca6b3dc2a26)
[2022-08-11T19:05:54-c4ec74a-62654df/netbsd-amd64-9_0](https://build.golang.org/log/070b4fee818231324badb590600980000d349fc2)
[2022-08-11T17:53:50-37a81b6-a526ec1/netbsd-amd64-9_0](https://build.golang.org/log/373391707f93fff54945c55648170d9dd390958c)
[2022-08-11T16:19:14-37a81b6-2340d37/netbsd-amd64-9_0](https://build.golang.org/log/1c1abf0fdf7307ffbe030628c0c37a2af50e044d)
[2022-08-11T12:53:59-b2156b5-3c200d6/netbsd-386-9_0](https://build.golang.org/log/dd3e35eeace9e0ab8bad2da68b3822e492084f55)
[2022-08-10T22:22:48-b2156b5-6b80b62/netbsd-amd64-9_0](https://build.golang.org/log/0e0cf575d88b65e91a55b8f070bf9b7ef3136e6e)
[2022-08-10T17:41:25-0ad49fd-f19f6c7/netbsd-amd64-9_0](https://build.golang.org/log/f1c0a3ff9bc966ba2ea145a3fc5b207e7da04422)
[2022-08-10T15:08:24-3950865-c81dfdd/netbsd-amd64-9_0](https://build.golang.org/log/49e68c6f9a3e02fea5a3560b3599fec748fe37a5)
[2022-08-10T02:14:09-6fa767d-5531838/plan9-386-0intro](https://build.golang.org/log/dd0540ff0994f1f4dabc184f1a3139bc92e459b0)
[2022-08-09T14:33:24-92d58ea-0981d9f/openbsd-386-70](https://build.golang.org/log/2257a9730544b80a3bbd32cd77d842bae30df216)
[2022-08-09T14:12:01-92d58ea-662a729/netbsd-amd64-9_0](https://build.golang.org/log/262bb87feffe594abd0bca78d7ff0762bce6ce6d)
[2022-08-09T13:39:27-92d58ea-9e8020b/netbsd-386-9_0](https://build.golang.org/log/5038ff991c57474969f20b56f7e0147b970f9d6f)
[2022-08-09T11:28:56-92d58ea-0f8dffd/netbsd-amd64-9_0](https://build.golang.org/log/6f487445444131ce88dc81395c61491a75b717b6)
[2022-08-08T18:10:56-fff6d6d-4bcc138/netbsd-amd64-9_0](https://build.golang.org/log/d7b15610ae881f54e8580b1df112b35fae495416)
[2022-08-08T15:33:45-06d96ee-0581d69/netbsd-amd64-9_0](https://build.golang.org/log/0f6a50f7330a08b10fbbb2b30592206aa78088d8)
[2022-08-08T15:07:46-06d96ee-cd54ef1/netbsd-amd64-9_0](https://build.golang.org/log/4bf9c1e647958f6f7e91f6a4af54f5c0d47a5ff9)
[2022-08-08T14:12:21-06d96ee-e761556/netbsd-amd64-9_0](https://build.golang.org/log/139292d4921bc45d1d4f7eaad29b8ab74d492337)
[2022-08-08T06:16:59-06d96ee-0f6ee42/darwin-amd64-11_0](https://build.golang.org/log/dcb2262105851e705bd8a54363d0f7eb12ced52d)
[2022-08-08T06:16:59-06d96ee-0f6ee42/netbsd-386-9_0](https://build.golang.org/log/e338e8cc5f896780178f4653ca14cb3c5420eee3)
[2022-08-06T15:20:00-06d96ee-0c4db1e/plan9-386-0intro](https://build.golang.org/log/5cca74b05c0a96fe84d714c05095b688cf142998)
[2022-08-05T19:51:08-06d96ee-4fb7e22/plan9-386-0intro](https://build.golang.org/log/6b5544e536b89cd2b350dc28831b3cf2c1b930d1)
[2022-08-04T20:05:03-81c7dc4-39728f4/netbsd-386-9_0](https://build.golang.org/log/a0e0e2e24dbcc85bc1112cde350e2aab2f68507e)
[2022-08-04T20:05:03-81c7dc4-39728f4/netbsd-amd64-9_0](https://build.golang.org/log/1cf98e0db8d30c95362f07d44c47c5363b8c3955)
[2022-08-04T20:04:16-3519aa2-39728f4/netbsd-386-9_0](https://build.golang.org/log/9395fd87814bc4d6344a3bbf72f427637a40ff9d)
[2022-08-04T19:57:25-763f65c-39728f4/netbsd-386-9_0](https://build.golang.org/log/e6a1d9cdf59a37ef2641727a09850df931bf6c76)
[2022-08-04T18:51:46-99fd76f-39728f4/openbsd-386-70](https://build.golang.org/log/d3aa446a547efa10e17e2f9096f34a1e7de84a34)
[2022-08-04T17:05:18-3e0a503-fb1bfd4/netbsd-amd64-9_0](https://build.golang.org/log/3eab42b91ac882d28586f90d833b6a7adadfaa8e)
[2022-08-04T15:50:11-3e0a503-fcdd099/netbsd-386-9_0](https://build.golang.org/log/f20346aaff38f3501b9586c4bd5bce30beeb544c)
[2022-08-04T15:50:11-3e0a503-44ff9bf/netbsd-amd64-9_0](https://build.golang.org/log/cc32154c3c01fea6178c088a401ce789b8cdfea2)
[2022-08-04T15:31:49-87f47bb-44ff9bf/plan9-386-0intro](https://build.golang.org/log/1a849764f69705f80e2b9215a4af08a35ca6b599)
[2022-08-04T14:58:59-87f47bb-4345620/netbsd-386-9_0](https://build.golang.org/log/1979e42d0a685eaba423a2b72abb5f01467f9d29)
[2022-08-04T10:32:51-3e0a503-a10afb1/linux-386-buster](https://build.golang.org/log/0575b7d9be6333dd398544d939a632c7bca98820)
[2022-08-03T21:02:27-8b9a1fb-f28fa95/plan9-386-0intro](https://build.golang.org/log/3bdc65bf0d8317c8060a9213e294bd69d8c9a2c6)
[2022-08-03T21:02:27-8b9a1fb-4345620/netbsd-386-9_0](https://build.golang.org/log/274203fd71753a2475dc09b150bf2223ccafc467)
[2022-08-03T18:07:40-d08f5dc-fcdd099/netbsd-386-9_0](https://build.golang.org/log/0356b836f12656f38f905a8b00195c0dc91f9f9c)
[2022-08-03T13:50:38-ddb90ec-c6a2dad/dragonfly-amd64-622](https://build.golang.org/log/2afbb152ac08399d2e748415c1e8237aba177f93)
[2022-08-03T13:50:38-ddb90ec-c6a2dad/plan9-386-0intro](https://build.golang.org/log/17a5aa41dccbd8d4d12f725824e944297efc759d)
[2022-08-03T12:09:24-ddb90ec-29b9a32/plan9-386-0intro](https://build.golang.org/log/b476964cf820ebb56acaf4873de238e9944c2fdc)
[2022-08-02T18:52:36-0d04f65-29b9a32/plan9-386-0intro](https://build.golang.org/log/8d8b0cf1e7abad05f3b5efc3d81f8b943459e208)
[2022-08-02T18:19:01-d025cce-be59153/netbsd-amd64-9_0](https://build.golang.org/log/d373872d8833fcd7943ed0c44a350b1ed0964171)
[2022-08-02T18:16:22-10cb435-d723df7/netbsd-amd64-9_0](https://build.golang.org/log/52dcc80905a7e4fb69b303d2e10b0853d7a4d249)
[2022-08-02T18:07:14-4d0b383-d723df7/netbsd-386-9_0](https://build.golang.org/log/32e87f0ad4c401d7b6898923db1ccf0e18e96a55)
[2022-08-02T18:07:14-4d0b383-d723df7/netbsd-amd64-9_0](https://build.golang.org/log/c45079cd676d8c78a4fb2e516c7f8c61e99cf932)
[2022-08-02T17:23:42-4d0b383-1b7e71e/darwin-amd64-nocgo](https://build.golang.org/log/f1e5f794c6590cf6ef6af5b32593bdb2dc4e691a)
[2022-08-02T16:05:48-4d0b383-f2a9f3e/netbsd-amd64-9_0](https://build.golang.org/log/615a1fe11bff97f99eea28f57de7379a57de05ff)
[2022-07-29T20:19:23-9580c84-9240558/windows-arm64-11](https://build.golang.org/log/902f203f4ca2a092814c8f9feae9f34403c03fc0)
[2022-07-28T20:06:00-8ea5687-d9242f7/darwin-amd64-nocgo](https://build.golang.org/log/12a2b665a640b80267a18e005b8f48cef599747b)
[2022-07-27T15:04:58-39a4e36-4248146/freebsd-386-13_0](https://build.golang.org/log/2285dd340580856181ca3d5dc0c60759238a178d)
[2022-07-26T18:43:08-6c8a6c4-d9242f7/aix-ppc64](https://build.golang.org/log/b396e3df87257d69b4dfdaf4a5f927b2109cb3f4)
[2022-07-25T20:44:49-2a6393f-24dc27a/darwin-amd64-10_14](https://build.golang.org/log/99081c715af7f107984bbf25ee529a1bb386afe1)
[2022-07-25T18:11:01-4375b29-795a88d/plan9-386-0intro](https://build.golang.org/log/cb5fe95e5d275800ef3139747fb602ad99ea159e)
[2022-07-25T14:16:17-178fdf9-64f2829/plan9-386-0intro](https://build.golang.org/log/d5eae87730ea926b99e5c20558b3f7d53adcaa7e)
[2022-07-22T20:12:19-7b605f4-c5da4fb/plan9-386-0intro](https://build.golang.org/log/745ec57924a1086a4044a42e8daaf9cdad4b755a)
[2022-07-21T20:11:06-ec1f924-c4a6d30/plan9-386-0intro](https://build.golang.org/log/4a72300281f575745ce47d3a3e719e2ad624395f)
[2022-07-15T15:11:26-22d1494-2aa473c/windows-386-2008-newcc](https://build.golang.org/log/76a64e26cc4949d727458d3d75bf0a7d957761ba)
[2022-07-15T14:27:36-1a4e02f-4651ebf/windows-arm64-10](https://build.golang.org/log/31cefa7b619aab91a17a2e86457aea315f08992f)
[2022-07-15T14:20:24-db8f89b-4651ebf/windows-arm64-10](https://build.golang.org/log/32b673e2683994bcdf4b3ca0031b2ba66d6fa5f2)
[2022-07-14T21:03:14-db8f89b-783ff7d/windows-arm64-11](https://build.golang.org/log/da6886000059b7db0800204df81e5ae4cd151a5b)
[2022-07-14T21:01:58-db8f89b-aa80228/darwin-arm64-11](https://build.golang.org/log/cbff206e69443d9ec55c0fb38c5b0f3205fe7ba9)
[2022-07-14T19:05:09-db8f89b-a906d3d/windows-arm64-10](https://build.golang.org/log/283ac24f2b8085b434b86ff5fa37d5762efcaa40)
[2022-07-14T15:54:36-db8f89b-266c70c/windows-arm64-10](https://build.golang.org/log/9b4cda8292abc11d4807641e8af88e1cf57b2fd3)
[2022-07-14T01:47:39-db8f89b-558785a/windows-arm64-11](https://build.golang.org/log/d9dc888e4b2ad7d0a1b9804a1dd87cc9e4329946)

</details>

We recently started waiting for all go command invocations when shutting down gopls regtests.  It appears that sometimes we kill the go command and still don't get a result from `cmd.Wait()`. For example, here:
https://build.golang.org/log/00046e0b005c7660d676a3a415561950048f756a

In that failure, the test runner looks otherwise healthy (other tests ran fast), and yet the goroutine stack clearly shows a go command hanging for 9 minutes here:
https://cs.opensource.google/go/x/tools/+/master:internal/gocommand/invoke.go;l=260;drc=f38573358cbedf46d64c5759ef41b72afcf0c5c0

@bcmills do you happen to have any idea of what might cause this?