From 4ab7f337678095f501c4b4dae199fd358feedc95 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 10 Dec 2023 23:00:29 +0200 Subject: [PATCH] retry spawn with longer timeout --- src/middleware/Controller.ts | 24 +++++++++++++++++++++++- src/middleware/shard/Shard.ts | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/middleware/Controller.ts b/src/middleware/Controller.ts index 33b0268..5aaac3d 100644 --- a/src/middleware/Controller.ts +++ b/src/middleware/Controller.ts @@ -134,13 +134,35 @@ class Controller extends EventEmitter } // const promises = []; + const retry: Shard[] = []; for (let i = 0; i < shardCount; i++) { const shard = this.createShard(shardCount); - await shard.spawn(90_000); + try + { + await shard.spawn(90_000); + } + catch (err) + { + this.logger.error(err as Error); + this.logger.info('Retrying shard', i); + retry.push(shard); + } // promises.push(); } + for (const shard of retry) + { + try + { + await shard.spawn(120_000); + } + catch + { + this.logger.error(`Shard ${shard.id} failed to spawn in time`); + } + } + // await Promise.all(promises); this.#logger.status(`Shards spawned, spawned ${this.#shards.size} shards. Took ${Date.now() - start} ms`); diff --git a/src/middleware/shard/Shard.ts b/src/middleware/shard/Shard.ts index 00aa467..a86d6cf 100644 --- a/src/middleware/shard/Shard.ts +++ b/src/middleware/shard/Shard.ts @@ -132,6 +132,7 @@ class Shard extends EventEmitter { const cleanup = () => { + this.#process?.kill(); clearTimeout(spawnTimeoutTimer); // eslint-disable-line @typescript-eslint/no-use-before-define this.off('ready', onReady); // eslint-disable-line @typescript-eslint/no-use-before-define this.off('disconnect', onDisconnect); // eslint-disable-line @typescript-eslint/no-use-before-define