vbauerster / mpb

multi progress bar for Go cli applications
The Unlicense
2.29k stars 123 forks source link

Sometimes a bar fails to clear after completing and calling `Wait` #68

Closed cipriancraciun closed 4 years ago

cipriancraciun commented 4 years ago

Although I've used BarRemoveOnComplete on AddBar, I am making sure SetTotal and SetCurrent are correctly set to be completed, and I'm waiting for Wait to complete, sometimes the bar fails to be removed after completion.

Through experimentation, I've observed that waiting after Wait the same amount of time (plus some extra) as I've set with mpb.WithRefreshRate, seems to solve the issue.

This makes me think there is perhaps a race condition happening inside Wait?

cipriancraciun commented 4 years ago

Based on some further experimentation it seems that although after Wait returns there are no more goroutines running (except the main one), in some cases the bar still is not removed, which points away from a potential race condition in the code, and towards a "logic" issue.

I have also made sure to os.Stderr.Sync () (which I've used for WithOutput), so the issue is not buffering.


I've also made sure to panic if Completed is false (before calling Wait), and also checked that BarCount is zero (after returning Wait). In all cases when the bar remained visible no panic exception occurred, which further leads towards mainly a display bug.

vbauerster commented 4 years ago

Thanks for reporting! Can you please check on latest master? I just pushed commits, which should fix this.

cipriancraciun commented 4 years ago

Yes, I can confirm that by using the latest commit the issue seems to be solved: https://github.com/vbauerster/mpb/commit/dc22c1ba454298ef392acdc1e720a905ab809974

Thanks! I'll close this issue. (If it resurfaces, I'll reopen it again.)