Skip to content

Commit

Permalink
fix: add flush timeout for logs (#1007)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Lombardi <[email protected]>
  • Loading branch information
luke-lombardi and Luke Lombardi authored Mar 3, 2025
1 parent b79cb5d commit a13fbed
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/abstractions/common/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/beam-cloud/beta9/pkg/types"
)

const (
flushLogsTimeout = 500 * time.Millisecond
)

type LogStreamOpts struct {
SendCallback func(o common.OutputMsg) error
ExitCallback func(exitCode int32) error
Expand Down Expand Up @@ -97,6 +101,25 @@ _stream:
exitCode = -1
}

// After the container exits, flush remaining logs for up to flushLogsTimeout milliseconds
flushLogsTimer := time.NewTimer(flushLogsTimeout)
defer flushLogsTimer.Stop()

_flush:
for {
select {
case o, ok := <-outputChan:
if !ok {
break _flush
}
if err := l.sendCallback(o); err != nil {
break _flush
}
case <-flushLogsTimer.C:
break _flush
}
}

if err := l.exitCallback(int32(exitCode)); err != nil {
break _stream
}
Expand Down

0 comments on commit a13fbed

Please sign in to comment.