The native Promise.race method doesn't clear the timer of the timeout promise after the actual promise completes thus the process will wait until the timeout promise is also complete. This means that if you set the timeout to 1h and our promise is completed after 1min then the process will wait for 59min before it exits.
Use this method instead:
export function race({promise, timeout, error}) {
let timer = null;
return Promise.race([
new Promise((resolve, reject) => {
timer = setTimeout(reject, timeout, error);
return timer;
}),
promise.then((value) => {
clearTimeout(timer);
return value;
})
]);
}