Skip to content

Commit f8e7459

Browse files
committed
Fix usage report block of k6 execution if it takes longer than 3s (#2938)
(cherry picked from commit 4463298)
1 parent eddb5a6 commit f8e7459

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

cmd/run.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,17 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
306306
// Init has passed successfully, so unless disabled, make sure we send a
307307
// usage report after the context is done.
308308
if !conf.NoUsageReport.Bool {
309-
backgroundProcesses.Add(2)
310-
reportCtx, reportCancel := context.WithCancel(globalCtx)
311-
reportDone := make(chan error)
309+
backgroundProcesses.Add(1)
312310
go func() {
311+
defer backgroundProcesses.Done()
312+
reportCtx, reportCancel := context.WithTimeout(globalCtx, 3*time.Second)
313+
defer reportCancel()
313314
logger.Debug("Sending usage report...")
314-
reportDone <- reportUsage(reportCtx, execScheduler)
315-
close(reportDone)
316-
backgroundProcesses.Done()
317-
}()
318-
go func() {
319-
select {
320-
case <-reportDone:
321-
case <-time.After(3 * time.Second):
315+
if rerr := reportUsage(reportCtx, execScheduler); rerr != nil {
316+
logger.WithError(rerr).Debug("Error sending usage report")
317+
} else {
318+
logger.Debug("Usage report sent successfully")
322319
}
323-
reportCancel()
324-
backgroundProcesses.Done()
325320
}()
326321
}
327322

0 commit comments

Comments
 (0)