From e952c8fa0918c709fef079e32afa427d083958f2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 18 May 2019 23:38:49 +0800 Subject: [PATCH] =?UTF-8?q?:whale:=20=E6=89=A7=E8=A1=8C=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- output/run.go | 6 ++++-- playground/run.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/output/run.go b/output/run.go index 0cadce1..fe84652 100644 --- a/output/run.go +++ b/output/run.go @@ -51,7 +51,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { var cmd *exec.Cmd if conf.Docker { fileName := filepath.Base(filePath) - cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName) + cmd = exec.Command("timeout", "-s", "9", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName) } else { cmd = exec.Command(filePath) curDir := filepath.Dir(filePath) @@ -154,7 +154,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { Processes.Remove(wSession, cmd.Process) channelRet["cmd"] = "run-done" - if 124 == cmd.ProcessState.ExitCode() { + // timeout: https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html + exitCode := cmd.ProcessState.ExitCode() + if 124 == exitCode || 125 == exitCode || 137 == exitCode { channelRet["output"] = "run program timeout in 5s\n" } else { channelRet["output"] = "\nrun program complete\n" diff --git a/playground/run.go b/playground/run.go index 79387d6..e8809ef 100644 --- a/playground/run.go +++ b/playground/run.go @@ -52,7 +52,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { var cmd *exec.Cmd if conf.Docker { fileName := filepath.Base(filePath) - cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName) + cmd = exec.Command("timeout", "-s", "9", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName) } else { cmd = exec.Command(filePath) curDir := filepath.Dir(filePath) @@ -156,7 +156,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { output.Processes.Remove(wSession, cmd.Process) channelRet["cmd"] = "run-done" - if 124 == cmd.ProcessState.ExitCode() { + // timeout: https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html + exitCode := cmd.ProcessState.ExitCode() + if 124 == exitCode || 125 == exitCode || 137 == exitCode { channelRet["output"] = "\nrun program timeout in 5s\n" } if nil != wsChannel {