From 6b4c3ee4c7c7b8cc3a2a73e96d9372c998703fa8 Mon Sep 17 00:00:00 2001 From: Seohyun Lee Date: Tue, 4 Jan 2022 21:01:09 +0900 Subject: [PATCH] fix: fixed bug that process not quiting --- src/runner/common.ts | 9 ++++++--- src/runner/util.ts | 17 +++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/runner/common.ts b/src/runner/common.ts index 44b6287..d759f3a 100644 --- a/src/runner/common.ts +++ b/src/runner/common.ts @@ -140,11 +140,14 @@ export default function commonJudge( } } else { let info = '', - err = stderr.split('\n') + err = stderr.split('\n'), + timeUsage = 0 while (!info.includes('|') && err.length) info = err.pop() || '' - const timeUsage = - parseFloat(info.split('m ')[1].split('s')[0]) * 1000 + try { + timeUsage = + parseFloat(info.split('m ')[1].split('s')[0]) * 1000 + } catch {} const memUsage = parseInt(info.split('|')[1]) subtaskMaxTimeUsage = Math.max( subtaskMaxTimeUsage, diff --git a/src/runner/util.ts b/src/runner/util.ts index 02ae8b9..d4e5941 100644 --- a/src/runner/util.ts +++ b/src/runner/util.ts @@ -23,7 +23,7 @@ export function execute( recursive = 0 ) { option = Object.assign({ input: '', timeout: 0, cwd: '' }, option) - return new Promise((resolve) => { + return new Promise(async (resolve) => { if (recursive > 3) { resolve({ resultType: ResultType.stdioError, @@ -38,20 +38,25 @@ export function execute( ...(option.cwd ? { cwd: option.cwd } : {}), }) child.stdin.on('error', async () => { - resolve(await execute(userName, exePath, option)) + if (!timeouted) { + await execute(`${userName}`, `pkill -u ${userName}`) + resolve(await execute(userName, exePath, option)) + } }) child.on('error', async () => { - resolve(await execute(userName, exePath, option)) + if (!timeouted) { + await execute(`${userName}`, `pkill -u ${userName}`) + resolve(await execute(userName, exePath, option)) + } }) let timeHandler: NodeJS.Timeout, timeouted = false if (option.timeout) - timeHandler = setTimeout(() => { + timeHandler = setTimeout(async () => { timeouted = true - ;(child.stdin as any).pause() - child.kill() + await execute(`${userName}`, `pkill -u ${userName}`) resolve({ resultType: ResultType.timeLimitExceeded, code: -1,