Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

fix(local): fix race in sg_start_test.go#63642

Merged
jhchabran merged 1 commit into
mainfrom
jh/dinf-82
Jul 4, 2024
Merged

fix(local): fix race in sg_start_test.go#63642
jhchabran merged 1 commit into
mainfrom
jh/dinf-82

Conversation

@jhchabran

@jhchabran jhchabran commented Jul 4, 2024

Copy link
Copy Markdown
Contributor

Fixes DINF-82; This was very much a rabbithole. A few things:

  • The race that @bobheadxi mentioned here https://github.com/sourcegraph/sourcegraph/pull/63405#discussion_r1648180713 wasn't from *output.Output being unsafe, but outputtest.Buffer as it happened again (see DINF-82)
  • Fixing the above led to discover 👇
  • There something messed up with cmds.start(), which sometimes ends up printing the command output after the exit message instead of before.
    • The crude sort.Strings(want|have) that was there already fixes that.
    • Dug around for a while, but didn't find anything yet, because that duct tape is probably hiding something fishy.
  • And without the sleep, it's possible to read the output from the outputtest.Buffer before the command outputs get written to it.
    • The time.Sleep(300 * time.Milliseconds) mitigates/hides that problem.

At least, this shouldn't blow up in CI and buys us time to fix the whole thing. We're tracking this in DINF-104. And out of 200 runs, I also stumbled once, on a race in progress_tty, tracked in DINF-105 (that packages is originally meant to be used by src-cli and was re-used for sg 3 years ago).

I'm pretty unhappy about the solution, but a bandage is better than nothing. While ideally, we should really reconsider dropping std.Output entirely in sg and use the good stuff from github.com/charmbracelet instead because we don't want to spend too much time on arcane terminal things ourselves, I'm much more about concerned the concurrency issues mentioned above. We'll circle back on this.

Test plan

CI + sg bazel test //dev/sg:sg_test --runs_per_test=100

@cla-bot cla-bot Bot added the cla-signed label Jul 4, 2024
@jhchabran jhchabran added the no-changelog Exclude this PR from the next changelog. label Jul 4, 2024
@jhchabran jhchabran requested a review from a team July 4, 2024 17:09
@jhchabran jhchabran merged commit 2dfeb48 into main Jul 4, 2024
@jhchabran jhchabran deleted the jh/dinf-82 branch July 4, 2024 17:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed no-changelog Exclude this PR from the next changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants