From a8f70bf8892d5040601969c90c0b89df75a78bf3 Mon Sep 17 00:00:00 2001
From: David Colburn <xero73@gmail.com>
Date: Thu, 11 Jul 2024 11:32:56 -0700
Subject: [PATCH] add timeout to chrome launch

---
 pkg/pipeline/source/web.go | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/pkg/pipeline/source/web.go b/pkg/pipeline/source/web.go
index 239abb3e..2b69332d 100644
--- a/pkg/pipeline/source/web.go
+++ b/pkg/pipeline/source/web.go
@@ -40,6 +40,7 @@ const (
 	endRecordingLog   = "END_RECORDING"
 
 	chromeFailedToStart = "chrome failed to start:"
+	chromeTimeout       = time.Second * 30
 )
 
 type WebSource struct {
@@ -83,8 +84,19 @@ func NewWebSource(ctx context.Context, p *config.PipelineConfig) (*WebSource, er
 		return nil, err
 	}
 
-	if err := s.launchChrome(ctx, p, p.Insecure); err != nil {
-		logger.Warnw("failed to launch chrome", err, "display", p.Display)
+	var err error
+	chromeErr := make(chan error, 1)
+	go func() {
+		chromeErr <- s.launchChrome(ctx, p, p.Insecure)
+	}()
+	select {
+	case err = <-chromeErr:
+		// chrome launch completed
+	case <-time.After(chromeTimeout):
+		err = errors.ErrPageLoadFailed("timed out")
+	}
+	if err != nil {
+		logger.Warnw("failed to launch chrome", err)
 		s.Close()
 		return nil, err
 	}