Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] Marking request error as nonessential error, added retry for session create request #940

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions selenium/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@ 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.String())
}

resp, err := httpClient.Do(req)
if err != nil {
sessReq.EssentialErrCh <- err
sessReq.NonEssentialErrCh <- err
return
}

Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down