Skip to content

Commit 6f66e6e

Browse files
committed
increase flush timeout and anchor it to send
1 parent 78c478c commit 6f66e6e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

agent/agent.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,8 @@ func (a *agent) trackScriptLogs(ctx context.Context, reader io.ReadCloser) (chan
919919
sendDone := make(chan struct{})
920920
send := make(chan []agentsdk.StartupLog, 1)
921921
go func() {
922-
flushTimeout := 100 * time.Millisecond
922+
flushTimeout := 250 * time.Millisecond
923923
flush := time.NewTimer(flushTimeout)
924-
flush.Stop()
925924

926925
var backlog []agentsdk.StartupLog
927926
defer func() {
@@ -957,6 +956,8 @@ func (a *agent) trackScriptLogs(ctx context.Context, reader io.ReadCloser) (chan
957956
}
958957

959958
if (done || flushed) && len(backlog) > 0 {
959+
flush.Stop() // Decrease the chance of a double flush.
960+
960961
// Retry uploading logs until successful or a specific
961962
// error occurs.
962963
for r := retry.New(time.Second, 5*time.Second); r.Wait(ctx); {
@@ -983,12 +984,14 @@ func (a *agent) trackScriptLogs(ctx context.Context, reader io.ReadCloser) (chan
983984
return
984985
}
985986
backlog = nil
987+
988+
// Only reset after send to ensure we send logs approximately
989+
// every flushTimeout (or every 100 rows).
990+
flush.Reset(flushTimeout)
986991
}
987992
if done {
988993
return
989994
}
990-
991-
flush.Reset(flushTimeout)
992995
}
993996
}()
994997

0 commit comments

Comments
 (0)