Skip to content

Commit

Permalink
fix: fixed bug that process not quiting
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Jan 4, 2022
1 parent 26cde9a commit 6b4c3ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/runner/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions src/runner/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function execute(
recursive = 0
) {
option = Object.assign({ input: '', timeout: 0, cwd: '' }, option)
return new Promise<ExecuteResult>((resolve) => {
return new Promise<ExecuteResult>(async (resolve) => {
if (recursive > 3) {
resolve({
resultType: ResultType.stdioError,
Expand All @@ -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,
Expand Down

0 comments on commit 6b4c3ee

Please sign in to comment.