Compare commits

..

2 Commits

Author SHA1 Message Date
fd0fd8954a fix: close captureOutput pipe before read 2026-01-19 16:37:22 +01:00
628db14f59 fix: avoid Update deadlock by unlocking before display 2026-01-19 16:37:15 +01:00
2 changed files with 6 additions and 7 deletions

View File

@@ -56,16 +56,16 @@ func newProgressIndicatorWithClock(total int, description string, c clock) *Prog
func (p *ProgressIndicator) Update(current int) { func (p *ProgressIndicator) Update(current int) {
p.mu.Lock() p.mu.Lock()
defer p.mu.Unlock()
p.current = current p.current = current
now := p.clock.Now() now := p.clock.Now()
if now.Sub(p.lastUpdate) < 100*time.Millisecond { if now.Sub(p.lastUpdate) < 100*time.Millisecond {
p.mu.Unlock()
return return
} }
p.lastUpdate = now p.lastUpdate = now
p.mu.Unlock()
p.display() p.display()
} }

View File

@@ -44,15 +44,14 @@ func captureOutput(fn func()) string {
r, w, _ := os.Pipe() r, w, _ := os.Pipe()
os.Stdout = w os.Stdout = w
defer func() {
_ = w.Close()
os.Stdout = old
}()
fn() fn()
_ = w.Close()
os.Stdout = old
var buf bytes.Buffer var buf bytes.Buffer
_, _ = io.Copy(&buf, r) _, _ = io.Copy(&buf, r)
_ = r.Close()
return buf.String() return buf.String()
} }