Bug 1864809 - Keep a reference to DNS workers while they are active. r=mkmelin

The worker is getting garbage collected before it has a chance to return with results.

Depends on D193866

Differential Revision: https://phabricator.services.mozilla.com/D193867

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Geoff Lankow 2023-11-17 07:23:09 +00:00
Родитель 19b668edba
Коммит 0d8c1e15b9
1 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -14,6 +14,9 @@ const NS_T_TXT = 16; // DNS_TYPE_TXT
const NS_T_SRV = 33; // DNS_TYPE_SRV const NS_T_SRV = 33; // DNS_TYPE_SRV
const NS_T_MX = 15; // DNS_TYPE_MX const NS_T_MX = 15; // DNS_TYPE_MX
// References to all active workers, so they don't get GC'ed while busy.
const workers = new Set();
export const DNS = { export const DNS = {
/** /**
* Constants for use with the lookup function. * Constants for use with the lookup function.
@ -33,13 +36,20 @@ export const DNS = {
* @param aTypeID The RR type to look up as a constant. * @param aTypeID The RR type to look up as a constant.
* @returns A promise resolved when completed. * @returns A promise resolved when completed.
*/ */
lookup(aName, aTypeID) { async lookup(aName, aTypeID) {
const worker = new BasePromiseWorker("resource:///modules/dnsWorker.js"); const worker = new BasePromiseWorker("resource:///modules/dnsWorker.js");
return worker.post("execute", [ workers.add(worker);
let result;
try {
result = await worker.post("execute", [
Services.appinfo.OS, Services.appinfo.OS,
"lookup", "lookup",
[...arguments], [...arguments],
]); ]);
} finally {
workers.delete(worker);
}
return result;
}, },
/** Convenience functions */ /** Convenience functions */