Skip to content

Commit

Permalink
Fix part timeout handling
Browse files Browse the repository at this point in the history
Cleanup frag stats handoff
  • Loading branch information
robwalch committed Feb 22, 2023
1 parent aae2d6c commit 05b7fe7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,7 @@ export default class BaseStreamController
return null;
}
if (fragCurrent && fragCurrent !== frag) {
logger.warn(`Expected current context to match fragCurrent`);
return { frag: fragCurrent, part, level };
frag.stats = fragCurrent.stats;
}
return { frag, part, level };
}
Expand Down
12 changes: 7 additions & 5 deletions src/loader/fragment-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
LoaderConfiguration,
FragmentLoaderContext,
} from '../types/loader';
import { getLoaderConfigWithoutReties } from '../utils/error-helper';
import type { HlsConfig } from '../config';
import type { BaseSegment, Part } from './fragment';
import type {
Expand Down Expand Up @@ -74,10 +75,9 @@ export default class FragmentLoader {
? new FragmentILoader(config)
: (new DefaultILoader(config) as Loader<FragmentLoaderContext>));
const loaderContext = createLoaderContext(frag);
const loadPolicy = Object.assign({}, config.fragLoadPolicy.default, {
timeoutRetry: null,
errorRetry: null,
});
const loadPolicy = getLoaderConfigWithoutReties(
config.fragLoadPolicy.default
);
const loaderConfig: LoaderConfiguration = {
loadPolicy,
timeout: loadPolicy.maxLoadTimeMs,
Expand Down Expand Up @@ -183,7 +183,9 @@ export default class FragmentLoader {
: (new DefaultILoader(config) as Loader<FragmentLoaderContext>));
const loaderContext = createLoaderContext(frag, part);
// Should we define another load policy for parts?
const loadPolicy = config.fragLoadPolicy.default;
const loadPolicy = getLoaderConfigWithoutReties(
config.fragLoadPolicy.default
);
const loaderConfig: LoaderConfiguration = {
loadPolicy,
timeout: loadPolicy.maxLoadTimeMs,
Expand Down
18 changes: 15 additions & 3 deletions src/utils/error-helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoadPolicy, RetryConfig } from '../config';
import { LoadPolicy, LoaderConfig, RetryConfig } from '../config';
import { ErrorDetails } from '../errors';
import { ErrorData } from '../types/events';

Expand Down Expand Up @@ -34,10 +34,22 @@ export function getRetryDelay(
);
}

export function getLoaderConfigWithoutReties(
loderConfig: LoaderConfig
): LoaderConfig {
return {
...loderConfig,
...{
errorRetry: null,
timeoutRetry: null,
},
};
}

export function shouldRetry(
retryConfig: RetryConfig | null,
retryConfig: RetryConfig | null | undefined,
retryCount: number,
httpStatus: number | undefined
httpStatus?: number | undefined
): retryConfig is RetryConfig & boolean {
return (
!!retryConfig &&
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xhr-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class XhrLoader implements Loader<LoaderContext> {
loadtimeout(): void {
const retryConfig = this.config?.loadPolicy.timeoutRetry;
const retryCount = this.stats.retry;
if (retryConfig && retryCount < retryConfig.maxNumRetry) {
if (shouldRetry(retryConfig, retryCount)) {
this.retry(retryConfig);
} else {
logger.warn(`timeout while loading ${this.context.url}`);
Expand Down

0 comments on commit 05b7fe7

Please sign in to comment.