fix: check if synthesizeEvent timeout error and add extra retry

This commit is contained in:
lilong.129
2025-07-23 20:51:54 +08:00
parent f4c541d62a
commit af227cfcd2

View File

@@ -183,6 +183,8 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
maxRetry = options.MaxRetryTimes
}
synthesizeEventRetryAdded := false
for attempt := 1; attempt <= maxRetry; attempt++ {
// Execute the request
rawResp, err = s.Request(method, urlStr, rawBody, opts...)
@@ -193,13 +195,20 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
return rawResp, nil
}
// only for WDA driver, check if "synthesizeEvent timeout" error and add extra retry
if strings.Contains(err.Error(), "synthesizeEvent timeout") && !synthesizeEventRetryAdded {
log.Warn().Err(err).Msg("synthesizeEvent timeout detected, adding one extra retry")
maxRetry++
synthesizeEventRetryAdded = true
}
// Notice: use DeviceHTTPDriverError when request driver failed
lastError = errors.Wrap(code.DeviceHTTPDriverError, err.Error())
log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, s.maxRetry)
log.Warn().Err(err).Msgf("request failed, attempt %d/%d", attempt, maxRetry)
// If this was the last attempt, break
if attempt == s.maxRetry {
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", s.maxRetry)
if attempt == maxRetry {
log.Error().Err(lastError).Msgf("all %d retry attempts failed, giving up", maxRetry)
break
}