stellar/go

ingest/ledgerbackend: Captive core's LogLineWriter should be closed synchronously

2opremio opened this issue · 0 comments

We just close the writer side of the pipe but don't wait for the goroutine to exit:

func (r *stellarCoreRunner) getLogLineWriter() io.Writer {
rd, wr := io.Pipe()
br := bufio.NewReader(rd)
// Strip timestamps from log lines from captive stellar-core. We emit our own.
dateRx := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3} `)
go func() {
levelRx := regexp.MustCompile(`\[(\w+) ([A-Z]+)\] (.*)`)
for {
line, err := br.ReadString('\n')
if err != nil {
break
}

This can cause an extra log line to be written after closing the backend, which causes problems in the new Soroban RPC integration tests. See https://github.com/stellar/soroban-rpc/actions/runs/9538438244/job/26287637351?pr=216#step:10:50

In this particular case, from a dangling goroutine is causing a race condition with Go's testing library.