From 030f24be24533aed32e4a4b9b6df6320dbe90224 Mon Sep 17 00:00:00 2001 From: 1computer1 Date: Tue, 21 May 2019 11:50:16 -0400 Subject: [PATCH] Add retry functionality --- config.example.json | 3 ++- src/struct/LanguageHandler.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config.example.json b/config.example.json index d9f7b57..25f2fc8 100644 --- a/config.example.json +++ b/config.example.json @@ -14,5 +14,6 @@ "memory": "256m", "cpus": "0.25", "timeout": 10000, - "concurrent": 10 + "concurrent": 10, + "retries": 2 } diff --git a/src/struct/LanguageHandler.js b/src/struct/LanguageHandler.js index a97955a..cf0523e 100644 --- a/src/struct/LanguageHandler.js +++ b/src/struct/LanguageHandler.js @@ -111,7 +111,7 @@ class LanguageHandler extends AkairoHandler { } } - evalCode({ language, code, options }) { + evalCode({ language, code, options, retries = 0 }) { const { id: dockerID = language.id, env = {} } = language.runWith(options); const queue = this.queues.get(dockerID); return queue.enqueue(async () => { @@ -132,9 +132,12 @@ class LanguageHandler extends AkairoHandler { try { await this.kill(name); } catch (err2) { - // Kill did not work, usually this is because of the container being killed just before. - // Happens when evals are done in quick succession and the container can't handle it. - // Solution is to lower the concurrent setting for that compiler. + // The container was not alive to be killed, i.e. multiple evals were occuring, + // one of them caused the container to be killed, the remaining evals all fail. + // Retry those remaining ones until they work! + if (retries < this.getCompilerConfig(dockerID, 'retries', 'number')) { + return this.evalCode({ language, code, options, retries: retries + 1 }); + } } throw err;