Skip to content

Commit

Permalink
fix(btcdctrl): read the output pipe continuously
Browse files Browse the repository at this point in the history
was missed by tests as this only appears on long-lived processes, eventually the pipe will run out of space causing `btcd` to hang.
  • Loading branch information
linden committed Oct 9, 2024
1 parent 069afc4 commit 4877c38
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions btcdctrl/btcdctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,23 @@ func (c *Controller) Start() error {

// Match the output configuration.
c.cmd.Stderr = c.cfg.Stderr

if c.cfg.Stdout != nil {
c.cmd.Stdout = io.MultiWriter(c.cfg.Stdout, pw)
} else {
c.cmd.Stdout = pw
}
c.cmd.Stdout = pw

// Execute the command.
err = c.cmd.Start()
if err != nil {
return err
}

var r io.Reader = pr

// Pipe the early output to stdout if configured.
if c.cfg.Stdout != nil {
r = io.TeeReader(pr, c.cfg.Stdout)
}

// Scan the stdout line by line.
scan := bufio.NewScanner(pr)
scan := bufio.NewScanner(r)

rpc := c.cfg.DisableRPC
p2p := false
Expand Down Expand Up @@ -314,6 +316,17 @@ func (c *Controller) Start() error {
return nil
}

// Discard as a fallback.
stdout := io.Discard

// Use the configured stdout by default.
if c.cfg.Stdout != nil {
stdout = c.cfg.Stdout
}

// The pipe needs to continuously be read, otherwise `btcd` will hang.
go io.Copy(stdout, pr)

deadline := time.Now().Add(30 * time.Second)

// Try to connect via RPC for 30 seconds.
Expand Down

0 comments on commit 4877c38

Please sign in to comment.