From a2c56593fdfa0794792bb244f347d1dac18128ed Mon Sep 17 00:00:00 2001 From: dmtgrinevich Date: Thu, 5 Oct 2023 11:04:03 +0000 Subject: [PATCH 1/3] Marking request error as nonessential error, added session create request retry --- selenium/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selenium/session.go b/selenium/session.go index ca17474f..a7d1c6ac 100644 --- a/selenium/session.go +++ b/selenium/session.go @@ -33,7 +33,7 @@ func startSession(ctx context.Context, req *http.Request, sessReq startSessReque resp, err := httpClient.Do(req) if err != nil { - sessReq.EssentialErrCh <- err + sessReq.NonEssentialErrCh <- err return } From 98abb11e710d7b2dc5702346473a77a55471e8ca Mon Sep 17 00:00:00 2001 From: dmtgrinevich Date: Thu, 5 Oct 2023 11:04:45 +0000 Subject: [PATCH 2/3] Marking request error as nonessential error, added session create request retry --- selenium/session.go | 19 ++++++++++++++----- service/service.go | 5 ++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/selenium/session.go b/selenium/session.go index a7d1c6ac..86a318cc 100644 --- a/selenium/session.go +++ b/selenium/session.go @@ -26,12 +26,21 @@ type startSessRequest struct { ResponseCh chan map[string]interface{} } -func startSession(ctx context.Context, req *http.Request, sessReq startSessRequest) { +func startSession(req *http.Request, sessReq startSessRequest) { req.Method = http.MethodPost req.Host = "localhost" - req = req.WithContext(ctx) + + retryCount := 2 + var resp *http.Response + var err error + for i := 0; i < retryCount; i++ { + resp, err = httpClient.Do(req) + if err == nil { + break + } + log.WithError(err).WithField("retry", i).Error("Failed to send request to ", req.URL.User.String()) + } - resp, err := httpClient.Do(req) if err != nil { sessReq.NonEssentialErrCh <- err return @@ -58,14 +67,14 @@ func startSession(ctx context.Context, req *http.Request, sessReq startSessReque sessReq.ResponseCh <- reply } -func WaitForSessionStart(ctx context.Context, request *http.Request) *startSessRequest { +func WaitForSessionStart(request *http.Request) *startSessRequest { sessReq := startSessRequest{ EssentialErrCh: make(chan error), NonEssentialErrCh: make(chan error), ResponseCh: make(chan map[string]interface{}), } - go startSession(ctx, request, sessReq) + go startSession(request, sessReq) return &sessReq } diff --git a/service/service.go b/service/service.go index 181cf441..1f068cac 100644 --- a/service/service.go +++ b/service/service.go @@ -181,16 +181,15 @@ func (s *startBasis) startDriverPhase(ctx context.Context) (essential *utils.Sel reqUrl.Scheme = "http" s.Log = s.Log.WithField("driver url", reqUrl) - startSessionRequest, err := http.NewRequest(http.MethodPost, reqUrl.String(), requestBody) + startSessionRequest, err := http.NewRequestWithContext(ctx, http.MethodPost, reqUrl.String(), requestBody) if err != nil { essential = utils.CreationErr(fmt.Errorf("failed to start driver"), err.Error()) s.Log.WithError(essential).Warn("Failed to start driver, stopping service...") return } - startSessionRequest.Header = s.Request.Header - waitRequest := selenium.WaitForSessionStart(ctx, startSessionRequest) + waitRequest := selenium.WaitForSessionStart(startSessionRequest) select { case <-ctx.Done(): s.Log.WithField("latency", time.Since(s.ServiceStart)).Info("driver startup timed out") From b4ae35ec328de5ec9a7f0bd630a84c073a831103 Mon Sep 17 00:00:00 2001 From: dmtgrinevich Date: Thu, 5 Oct 2023 11:14:15 +0000 Subject: [PATCH 3/3] fixed log's error message --- selenium/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selenium/session.go b/selenium/session.go index 86a318cc..c1d084e5 100644 --- a/selenium/session.go +++ b/selenium/session.go @@ -38,7 +38,7 @@ func startSession(req *http.Request, sessReq startSessRequest) { if err == nil { break } - log.WithError(err).WithField("retry", i).Error("Failed to send request to ", req.URL.User.String()) + log.WithError(err).WithField("retry", i).Error("Failed to send request to ", req.URL.String()) } if err != nil {