Skip to content

Commit

Permalink
refactor: [BE] 코드 타임아웃 리팩터링
Browse files Browse the repository at this point in the history
timeout : promise에서 옵션 방식으로 수정
  • Loading branch information
HKLeeeee committed Dec 17, 2023
1 parent 1d61a2d commit 87b8771
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions backEnd/running/src/codes/codes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ export class CodesService {
try {
const childProcess = spawn(commandParts[0], commandParts.slice(1), {
env: { STOP: "DON'T TRY TO ATTACK!!! PLZ..." },
timeout: this.timeOut,
killSignal: this.killSignal,
});
const timer = setTimeout(() => {
this.logger.log('timeout!');
childProcess.kill(this.killSignal);
}, this.timeOut);

childProcess.stdout.on('data', (data) => {
stdout.push(data);
Expand All @@ -96,10 +94,10 @@ export class CodesService {

childProcess.on('close', (code, signal) => {
this.logger.log(`child process exited with code ${code}, ${signal}`);
clearTimeout(timer);
const out = Buffer.concat(stdout).toString();
let err = Buffer.concat(stderr).toString();
if (this.isTimeout(code, signal)) {
this.logger.log('timeout!');
err = Messages.TIMEOUT;
}
resolve({ stdout: out, stderr: err });
Expand Down

0 comments on commit 87b8771

Please sign in to comment.