mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-25 07:48:24 +00:00
fixed bug on hanging on shutdown
improved shutdown sequence
This commit is contained in:
@@ -154,6 +154,7 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
|
|
||||||
// FIXME: see issue with downloadManager below
|
// FIXME: see issue with downloadManager below
|
||||||
let aria2cExec: ChildProcess | undefined;
|
let aria2cExec: ChildProcess | undefined;
|
||||||
|
let arai2cExited = false;
|
||||||
let downloadManager: DownloadManager | undefined;
|
let downloadManager: DownloadManager | undefined;
|
||||||
await portfinder.getPortPromise().then(
|
await portfinder.getPortPromise().then(
|
||||||
port => {
|
port => {
|
||||||
@@ -161,8 +162,14 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
// Launch aria2c
|
// Launch aria2c
|
||||||
aria2cExec = exec(
|
aria2cExec = exec(
|
||||||
`aria2c --enable-rpc --pause=true --rpc-listen-port=${port}`, (err, stdout, stderr) => {
|
`aria2c --enable-rpc --pause=true --rpc-listen-port=${port}`, (err, stdout, stderr) => {
|
||||||
logger.error(err?.message ?? (stderr || stdout));
|
if (err) {
|
||||||
process.exit(ERROR_CODE.ARIA2C_CRASH);
|
logger.error(err.message ? err.message : (stderr ? stderr : stdout));
|
||||||
|
process.exit(ERROR_CODE.ARIA2C_CRASH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.verbose('Aria2c proces exited');
|
||||||
|
arai2cExited = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// bind webSocket
|
// bind webSocket
|
||||||
@@ -330,10 +337,21 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
logger.info(`Video no.${videos.indexOf(video) + 1} downloaded!!\n\n`);
|
logger.info(`Video no.${videos.indexOf(video) + 1} downloaded!!\n\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info('Exiting, this will take some seconds...');
|
||||||
|
|
||||||
logger.debug('[destreamer] closing downloader socket');
|
logger.debug('[destreamer] closing downloader socket');
|
||||||
await downloadManager?.close();
|
await downloadManager?.close();
|
||||||
logger.debug('[destreamer] closed downloader. Stopping aria2c deamon');
|
logger.debug('[destreamer] closed downloader. Waiting aria2c deamon exit');
|
||||||
aria2cExec?.kill('SIGINT');
|
let tries = 0;
|
||||||
|
while (!arai2cExited) {
|
||||||
|
if (tries < 10) {
|
||||||
|
tries++;
|
||||||
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aria2cExec?.kill('SIGINT');
|
||||||
|
}
|
||||||
|
}
|
||||||
logger.debug('[destreamer] stopped aria2c');
|
logger.debug('[destreamer] stopped aria2c');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -368,17 +386,8 @@ async function main(): Promise<void> {
|
|||||||
`\thttps://web.microsoftstream.com/video/${guid} => ${outDirs[i]} \n`).join(''));
|
`\thttps://web.microsoftstream.com/video/${guid} => ${outDirs[i]} \n`).join(''));
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: [FATAL] we have 4 lingering socket connections and
|
// fuck you bug, I WON!!!
|
||||||
I can't figure them out.
|
|
||||||
To see them use debug mode and after execution (I suggested using
|
|
||||||
--simulate) use 'process._getActiveHandles();' and
|
|
||||||
'process._getActiveRequests();' in the debug console to see lingering
|
|
||||||
Handles (where you can find the sockets) or Requests */
|
|
||||||
await downloadVideo(videoGUIDs, outDirs, session);
|
await downloadVideo(videoGUIDs, outDirs, session);
|
||||||
|
|
||||||
// workaround for issue above
|
|
||||||
process.exit(0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user