Skip to content

Bar dupes when adding new bar #139

@Bios-Marcel

Description

@Bios-Marcel

So, for some reason my bar is duplicating. It always happens during the same situation. My assumption is that it is a race condition. But adding locks around all calls that touch the bar didn't help.

So, am I fundamentally missunderstanding something or could it be a bug?

I can try to make a minimally reproducable example and test in on different terminals and distros if you want.

This case happened on Windows 11, Powershell Core, Wezterm.

wezterm-gui_HlroIhodAw.mp4
	progressBars := mpb.New()
LOOP:
	for {
		select {
		case response, open := <-responses:
			if !open && response == nil && extract != nil {
				// Close extract and let it finish tasks, as its buffered.
				close(extract)
				extract = nil
				continue LOOP
			}

			bar := progressBars.AddBar(100,
				mpb.PrependDecorators(
					decor.Name(
						"Downloading: "+filepath.Base(response.Request.URL().String()),
						decor.WC{C: decor.DindentRight | decor.DextraSpace},
					),
					decor.OnComplete(decor.AverageETA(decor.ET_STYLE_GO), "done"),
				),
				mpb.AppendDecorators(decor.Percentage()),
			)
			go func() {
				ticker := time.NewTicker(200 * time.Millisecond)
				defer ticker.Stop()
				for {
					select {
					case <-ticker.C:
						bar.SetCurrent(int64(response.Progress() * 100))
					case <-response.Done:

						if err := response.Err(); err != nil {
							bar.Abort(true)
							errChan <- fmt.Errorf("error during download: %w", err)
						} else {
							bar.SetCurrent(100)
						}

						extract <- response.Request.Context().Value("item").(Downloadable)
						return
					}
				}
			}()
		case err := <-errChan:
			return err
		case downloadedFile, open := <-extract:
			if !open {
				break LOOP
			}

			bar := progressBars.AddBar(100,
				mpb.PrependDecorators(
					decor.Name(
						"Extracting: "+filepath.Base(downloadedFile.URL),
						decor.WC{C: decor.DindentRight | decor.DextraSpace},
					),
					decor.OnComplete(decor.AverageETA(decor.ET_STYLE_GO), "done"),
				),
				mpb.AppendDecorators(decor.Percentage()),
			)
			for i := 0; i < 10; i++ {
				time.Sleep(200 * time.Millisecond)
				bar.IncrBy(10)
			}

			if err := scoop.extract(app, resolvedApp, cacheDir, versionDir, downloadedFile, arch); err != nil {
				return fmt.Errorf("error extracting file: %w", err)
			}
		}
	}

	progressBars.Shutdown()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions