dagger / dagger

An engine to run your pipelines in containers
https://dagger.io
Apache License 2.0
10.66k stars 569 forks source link

🐞 Dagger CLI panics when running with --progress tty in BuildKite #5909

Open zzztimbo opened 9 months ago

zzztimbo commented 9 months ago

What is the issue?

Running the Dagger CLI using the --progress tty flag causes a panic in BuildKite. It would be nice to view the tty output in Buildkite. It works in Github Actions.

The error message seems similar to this issue: https://github.com/charmbracelet/bubbles/issues/20

Log output

Caught panic:
--
  |  
  | runtime error: slice bounds out of range [3:1]
  |  
  | Restoring terminal...
  |  
  | goroutine 1 [running]:
  | runtime/debug.Stack()
  | /usr/local/go/src/runtime/debug/stack.go:24 +0x65
  | runtime/debug.PrintStack()
  | /usr/local/go/src/runtime/debug/stack.go:16 +0x19
  | github.com/charmbracelet/bubbletea.(*Program).Run.func1()
  | /go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:440 +0x95
  | panic({0x12137c0, 0xc00001a078})
  | /usr/local/go/src/runtime/panic.go:890 +0x263
  | github.com/charmbracelet/bubbles/viewport.Model.visibleLines(...)
  | /go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/viewport/viewport.go:123
  | github.com/charmbracelet/bubbles/viewport.(*Model).GotoBottom(0xc000355388?)
  | /go/pkg/mod/github.com/charmbracelet/bubbles@v0.16.1/viewport/viewport.go:237 +0x19b
  | github.com/vito/progrock.(*Model).render(0xc000355340)
  | /go/pkg/mod/github.com/vito/progrock@v0.10.2-0.20230913234310-64b4a1cfb007/model.go:446 +0x275
  | github.com/vito/progrock.(*Model).Update(0xc000355340, {0x11b0780?, 0xc000132018?})
  | /go/pkg/mod/github.com/vito/progrock@v0.10.2-0.20230913234310-64b4a1cfb007/model.go:357 +0xae
  | github.com/charmbracelet/bubbletea.(*Program).eventLoop(0xc000000000, {0x1469a90?, 0xc000355340?}, 0x0?)
  | /go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:373 +0x646
  | github.com/charmbracelet/bubbletea.(*Program).Run(0xc000000000)
  | /go/pkg/mod/github.com/charmbracelet/bubbletea@v0.24.2/tea.go:503 +0x87d
  | github.com/vito/progrock.(*UI).Run(0x1463528?, {0x146b2b8, 0xc0000441e8}, 0xc0006bf9c0?, 0xc0006bf9f8?)
  | /go/pkg/mod/github.com/vito/progrock@v0.10.2-0.20230913234310-64b4a1cfb007/model.go:215 +0x556
  | main.inlineTUI({0x146b2b8, 0xc0000441e8}, {{0x0, 0x0}, {0x0, 0x0, 0x0}, {0xc0003e07b0, 0x24}, {0xc0003e07e0, ...}, ...}, ...)
  | /app/cmd/dagger/engine.go:172 +0x190
  | main.withEngineAndTUI({0x146b2b8, 0xc0000441e8}, {{0x0, 0x0}, {0x0, 0x0, 0x0}, {0xc0003e07b0, 0x24}, {0xc0003e07e0, ...}, ...}, ...)
  | /app/cmd/dagger/engine.go:73 +0x1c5
  | main.run({0x146b2b8, 0xc0000441e8}, {0xc0005a4760, 0x2, 0x2})
  | /app/cmd/dagger/run.go:93 +0x22b
  | main.Run(0x1d20980?, {0xc0005a4760?, 0x2?, 0x2?})
  | /app/cmd/dagger/run.go:70 +0x3c
  | github.com/spf13/cobra.(*Command).execute(0x1d20980, {0xc0005a4720, 0x2, 0x2})
  | /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944 +0x847
  | github.com/spf13/cobra.(*Command).ExecuteC(0x1d203c0)
  | /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd
  | github.com/spf13/cobra.(*Command).Execute(...)
  | /go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
  | main.main()
  | /app/cmd/dagger/main.go:96 +0x32
  | ┣─╮
  | │ ▽ init
  | │ █ [0.00s] connect
  | │ ┣ [0.00s] starting engine
  | ┻ ┻
  |  
  | ⧗ 0.00s ⣾ 1  • connect: starting engine

Steps to reproduce

https://github.com/zzztimbo/dagger-buildkite-debug/blob/main/.buildkite/pipeline.yml#L11-L16

SDK version

N/A

OS version

N/A

jedevc commented 9 months ago

cc @vito

vito commented 9 months ago

Looked into this briefly, my best guess is that it's an upstream issue, but don't have time to dig further right now - sorry.

I was curious how to get Go to panic in that way, so here's a repro: https://go.dev/play/p/VLumHZPF1uq

tl;dr you need to pass an out-of-order slice selection, but specifically using calculated values instead of static ones; if you do foo[3:1] you'll get a compliation error instead complaining that 3 > 1.

The calculation is happening here: https://github.com/charmbracelet/bubbles/blob/167e9067bc4eb2566334f33787cdfdf1bcc25124/viewport/viewport.go#L121-L123

bgroupe commented 5 months ago

FWIW I'm also having this issue running dagger from Codefresh, which has an automatic secret masking feature that is potentially dynamically rewriting stdout that apparently Buildkite does also https://github.com/buildkite/agent/pull/1109.

vito commented 5 months ago

For anyone stuck on this, I believe the fix is to configure a window size. Try this:

stty columns 80 # this might be enough
stty rows 80    # if not, try this too