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

Fix fallback to inline worker when exception is thrown in worker #5270

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
// (undocumented)
protected onvseeking: EventListener | null;
// (undocumented)
protected recoverWorkerError(data: ErrorData): void;
// (undocumented)
protected reduceMaxBufferLength(threshold?: number): boolean;
// (undocumented)
protected resetFragmentErrors(filterType: PlaylistLevelType): void;
Expand Down
3 changes: 3 additions & 0 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ class AudioStreamController
this.resetLoadingState();
}
break;
case ErrorDetails.INTERNAL_EXCEPTION:
this.recoverWorkerError(data);
break;
default:
break;
}
Expand Down
7 changes: 7 additions & 0 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,13 @@ export default class BaseStreamController
}
}

protected recoverWorkerError(data: ErrorData) {
if (data.event === 'demuxerWorker') {
this.resetTransmuxer();
this.resetLoadingState();
}
}

set state(nextState) {
const previousState = this._state;
if (previousState !== nextState) {
Expand Down
3 changes: 3 additions & 0 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ export default class StreamController
this.resetLoadingState();
}
break;
case ErrorDetails.INTERNAL_EXCEPTION:
this.recoverWorkerError(data);
break;
default:
break;
}
Expand Down
27 changes: 17 additions & 10 deletions src/demux/transmuxer-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export default class TransmuxerInterface {
const error = new Error(
`${event.message} (${event.filename}:${event.lineno})`
);
this.useWorker = false;
this.error = null;
config.enableWorker = false;
logger.warn('Exception in webworker, fallback to inline');
this.hls.trigger(Events.ERROR, {
type: ErrorTypes.OTHER_ERROR,
Expand All @@ -105,10 +104,7 @@ export default class TransmuxerInterface {
logger.error(
'Error while initializing DemuxerWorker, fallback to inline'
);
if (worker) {
// revoke the Object URL that was used to create transmuxer worker, so as not to leak it
self.URL.revokeObjectURL(worker.objectURL);
}
this.resetWorker();
this.error = null;
this.transmuxer = new Transmuxer(
this.observer,
Expand All @@ -117,7 +113,6 @@ export default class TransmuxerInterface {
vendor,
id
);
this.worker = null;
}
} else {
this.transmuxer = new Transmuxer(
Expand All @@ -130,12 +125,24 @@ export default class TransmuxerInterface {
}
}

resetWorker(): void {
const worker = this.worker;
if (worker) {
if (worker?.objectURL) {
// revoke the Object URL that was used to create transmuxer worker, so as not to leak it
self.URL.revokeObjectURL(worker.objectURL);
}
worker.removeEventListener('message', this.onwmsg);
worker.onerror = null;
worker.terminate();
this.worker = null;
}
}

destroy(): void {
const w = this.worker;
if (w) {
w.removeEventListener('message', this.onwmsg);
w.terminate();
this.worker = null;
this.resetWorker();
this.onwmsg = undefined;
} else {
const transmuxer = this.transmuxer;
Expand Down