Skip to content

Conversation

@luislavena
Copy link
Contributor

On certain scenarios, Docker will report a bigger Current than Total, resulting in an overflow when trying to show the progress of the push for the image.

Cap progress percentage at 100 to prevent index out of bounds errors in progress display, as sometimes the calculation could exceed 100.

On certain scenarios, Docker will report a bigger Current than
Total, resulting in an overflow when trying to show the progress
of the push for the image.

Cap progress percentage at 100 to prevent index out of bounds
errors in progress display, as sometimes the calculation could
exceed 100.
@luislavena
Copy link
Contributor Author

Hola! Encountered this issue while working on #152. In some cases I would randomly get the following overflow:

$ ./uncloud --uncloud-config ./blatta.yaml image push ghcr.io/traefik/whoami:v1.9.0 --platform linux/amd64 -m all
[+] Pushing image ghcr.io/traefik/whoami:v1.9.0 to cluster 2/10
 ✔ Proxy to unregistry on blatta41 (localhost:55836 → 10.210.0.1:5000) Started                                        0.0s
 ✔ Proxy to unregistry on blatta42 (localhost:55837 → 10.210.1.1:5000) Started                                        0.0s
 ⠋ Pushing ghcr.io/traefik/whoami:v1.9.0 to blatta41 [⠀⣿⠀] 294.4kB / 6.483MB  Pushing                                 0.1s
   ⠋ Layer cc36d5c6c0de on blatta41: Pushing                   [>                                                  ]  66.05[+] Pushing image ghcr.io/traefik/whoami:v1.9.0 to cluster 5/10
 ✔ Proxy to unregistry on blatta41 (localhost:55836 → 10.210.0.1:5000) Started                                        0.0s  ✔ Proxy to unregistry on blatta42 (localhost:55837 → 10.210.1.1:5000) Started                                        0.0s
panic: runtime error: index out of range [14] with length 9    [>                                                  ]  10.75kB/1.071MB0.1s
goroutine 97 [running]:fik/whoami:v1.9.0 to blatta42 [⠀⣿⠀]  Pushing                                                   0.1s
github.com/docker/compose/v2/pkg/progress.(*ttyWriter).lineText(0x14000808500, {{0x14000822280, 0x41}, {0x0, 0x0}, {0x0, 0x0}, 0x0, {0x1024430a5, 0x7}, ...}, ...)
   ⠋ Lay/Users/luis/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/tty.go:255 +0x8f0================>]  217.github.com/docker/compose/v2/pkg/progress.(*ttyWriter).print(0x14000808500)
   ⠋ Lay/Users/luis/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/tty.go:197 +0x624                    0.0s
github.com/docker/compose/v2/pkg/progress.(*ttyWriter).Start(0x14000808500, {0x1030cee00, 0x104430160})
        /Users/luis/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/tty.go:64 +0x6c
github.com/docker/compose/v2/pkg/progress.RunWithStatus.func1()
        /Users/luis/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/writer.go:103 +0x34
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /Users/luis/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:93 +0x4c
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        /Users/luis/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x90

This change solves that. Not the smartest or cleanest, but definitely the pragmatic one 😆

Thank you!
❤️ ❤️ ❤️

Copy link
Owner

@psviderski psviderski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking your time to investigate the issue and implementing the fix.
Legend! 💯

if jm.Progress.Total > 0 {
percent = int(jm.Progress.Current * 100 / jm.Progress.Total)
// Cap percent at 100 to prevent index out of bounds in progress display.
// Docker can report Current > Total in some cases (e.g., compression).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wow, didn't expect that from docker 😆. Thank you for the fix! ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit surprised when saw this 🤣

Copy link
Owner

@psviderski psviderski Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What also surprised is that Docker Compose doesn't have this check and my implementation was based on this: https://github.com/docker/compose/blob/main/pkg/compose/push.go#L130-L170

Maybe there is something specific in the unregistry implementation that triggered this 🤷
Anyway, I like the fix and the progress bar correctness is not something I'd like to spend my time on haha 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly in all my years, I've never used docker compose push, so I don't know 🫣

Let's keep it that way 😂

@psviderski psviderski merged commit 0153e9f into psviderski:main Oct 22, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants