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

Custom shouldRetry in retryConfig #5658

Conversation

PavelFomin90
Copy link
Contributor

This PR will...

Adds the ability to set a custom function shouldRetry via retryConfig, which overrides default

Why is this Pull Request needed?

Was recommended to add this improvement in #5647 in cases when user need to have possibility to override default shouldRetry

Resolves issues:

#5647

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@PavelFomin90 PavelFomin90 changed the title Custom shoudRetry in retryConfig Custom shouldRetry in retryConfig Jul 13, 2023
Comment on lines 55 to 60
return (
!!retryConfig &&
retryCount < retryConfig.maxNumRetry &&
(retryForHttpStatus(httpStatus) || !!isTimeout)
(retryConfig.shouldRetry
? retryConfig.shouldRetry()
: retryCount < retryConfig.maxNumRetry &&
(retryForHttpStatus(httpStatus) || !!isTimeout))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retryConfig.shouldRetry should take all the arguments of this shouldRetry helper, plus the result of this helper:

export function shouldRetry(
  retryConfig: RetryConfig | null | undefined,
  retryCount: number,
  isTimeout: boolean,
  httpStatus?: number | undefined
): retryConfig is RetryConfig & boolean {
  if (!retryConfig) {
    return false;
  }
  const retry = retryCount < retryConfig.maxNumRetry && (retryForHttpStatus(httpStatus) || !!isTimeout));
  return (
    (retryConfig.shouldRetry 
      ? retryConfig.shouldRetry(retryConfig, retryCount, isTimeout, httpStatus, retry)
      : retry
     );
}

And then the signature for retryConfig.shouldRetry should be modified to expect these arguments (see comment inline).

src/config.ts Outdated Show resolved Hide resolved
@robwalch robwalch added this to the 1.5.0 milestone Jul 13, 2023
fixies after review
@paxelpixel
Copy link
Contributor

This and #5647 are interesting because even if shouldRetry is false In the case of 404 it still retries the same partial segment number instead of moving on to the next one. and it does follow the maxNumRetry, it just doesn't follow the retryDelayMs

@PavelFomin90
Copy link
Contributor Author

PavelFomin90 commented Jul 14, 2023

This and #5647 are interesting because even if shouldRetry is false In the case of 404 it still retries the same partial segment number instead of moving on to the next one. and it does follow the maxNumRetry, it just doesn't follow the retryDelayMs

In #5647 it’s happening with the last segment in levels in live streams, because levels doesn’t have #EXT-ENDLIST. In VOD it works as expected

@PavelFomin90
Copy link
Contributor Author

This and #5647 are interesting because even if shouldRetry is false In the case of 404 it still retries the same partial segment number instead of moving on to the next one. and it does follow the maxNumRetry, it just doesn't follow the retryDelayMs

In #5647 it’s happening with the last segment in levels in live streams, because levels doesn’t have #EXT-ENDLIST. In VOD it works as expected

I was wrong, it's also try to refetch last ts-fragment with 404 in level in VOD

@robwalch
Copy link
Collaborator

I was wrong, it's also try to refetch last ts-fragment with 404 in level in VOD

With #5647, the stream controller is loop-loading the failed segment after the retry logic has deemed that hls.js should not retry on 4xx errors. With no alternatives, the failed segment should probably be treated as a gap, at least for a short period (the expectation seems to have been that retryDelay would be that period). This change would allow an application to force the retry.

If you expect a different behavior for handling the segment at the live edge when there are no alternative options (single variant/level playback), please comment in #5647.

Comment on lines +61 to +69
return retryConfig.shouldRetry
? retryConfig.shouldRetry(
retryConfig,
retryCount,
isTimeout,
httpStatus,
retry
)
: retry;
Copy link
Collaborator

@robwalch robwalch Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let others chime in, but thinking about this some more; we might want to handle this in the loaders so that the LoaderContext and maybe stats are also passed in. That way an app can performa specific actions based on individual request errors and runtime performance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelFomin90, This could be handled in a follow up PR if you don't want to take it on. It just needs to be finalized before 1.5.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, of couse.
I'm not sure, that I have enough time and skill to dive deeper in context, so I'll prefer not to take this responsibility

@robwalch robwalch changed the base branch from master to feature/custom-should-retry August 22, 2023 23:49
@robwalch robwalch merged commit 2e0bb0e into video-dev:feature/custom-should-retry Aug 22, 2023
12 checks passed
robwalch added a commit that referenced this pull request Aug 31, 2023
* Custom shoudRetry in retryConfig (#5658)

Co-authored-by: pfomin <pfomin@ivi.ru>

* Replace httpStatus argument with LoaderResponse in config.shouldRetry #5658

---------

Co-authored-by: Pavel Fomin <me@pavelfomin.ru>
Co-authored-by: pfomin <pfomin@ivi.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants