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 MultiThread debug element memory leak #1564

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
22 changes: 15 additions & 7 deletions src/main_thread/init/multi_thread_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
private _currentMediaSourceCanceller: TaskCanceller;

/**
* Stores the resolvers and the current messageId that is sent to the web worker to receive segment sink metrics.
* Stores the resolvers and the current messageId that is sent to the web worker to
* receive segment sink metrics.
* The purpose of collecting metrics is for monitoring and debugging.
*/
private _segmentMetrics: {
lastMessageId: number;
resolvers: Record<number, (value: ISegmentSinkMetrics | undefined) => void>;
resolvers: Map<number, (value: ISegmentSinkMetrics | undefined) => void>;
};

/**
Expand All @@ -135,7 +136,7 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
this._currentContentInfo = null;
this._segmentMetrics = {
lastMessageId: 0,
resolvers: {},
resolvers: new Map(),
};
this._queuedWorkerMessages = null;
}
Expand Down Expand Up @@ -1121,10 +1122,9 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
if (this._currentContentInfo?.contentId !== msgData.contentId) {
return;
}
const resolveFn = this._segmentMetrics.resolvers[msgData.value.messageId];
const resolveFn = this._segmentMetrics.resolvers.get(msgData.value.messageId);
if (resolveFn !== undefined) {
resolveFn(msgData.value.segmentSinkMetrics);
delete this._segmentMetrics.resolvers[msgData.value.messageId];
} else {
Florent-Bouisset marked this conversation as resolved.
Show resolved Hide resolved
log.error("MTCI: Failed to send segment sink store update");
}
Expand Down Expand Up @@ -1589,11 +1589,19 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
value: { messageId },
});
return new Promise((resolve, reject) => {
this._segmentMetrics.resolvers[messageId] = resolve;
const rejectFn = (err: CancellationError) => {
delete this._segmentMetrics.resolvers[messageId];
cancelSignal.deregister(rejectFn);
this._segmentMetrics.resolvers.delete(messageId);
return reject(err);
};
this._segmentMetrics.resolvers.set(
messageId,
(value: ISegmentSinkMetrics | undefined) => {
cancelSignal.deregister(rejectFn);
this._segmentMetrics.resolvers.delete(messageId);
resolve(value);
},
);
cancelSignal.register(rejectFn);
});
};
Expand Down
Loading