Skip to content

Commit 136c41e

Browse files
committed
sandbox: timeout runsc commands
The current mechanism for forcing a process to die ater a timeout is not sufficient. This change fixes issues that were causing processes to run forever on the sandbox. - Gracefully terminate processes before we kill them inside of our gVisor process. This helps capture valuable debug output for the user. - Return a friendlier error when our run context times out on the playground. - Add a test that timeouts are handled gracefully. - Reduce concurrent goroutines in our sandbox run handler by replacing goroutine copy functions with a custom writer (limitedWriter) that returns an error if too much output is returned, halting the program. - Custom writers (limitedWriter, switchWriter) also fix timing errors when calling Wait() too soon on a Command, before we have read all of the data. It also fixes a different error from trying to read data after a program has terminated. - Remove goroutine from startContainer, and use a ticker + context timeout for synchronization. Updates golang/go#25224 Updates golang/go#38343 Change-Id: Ie9d65220e5c4f39272ea70b45c4b472bcd7069bb Reviewed-on: https://go-review.googlesource.com/c/playground/+/227652 Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 0a10c62 commit 136c41e

File tree

5 files changed

+388
-118
lines changed

5 files changed

+388
-118
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runlocal:
1616

1717
test_go:
1818
# Run fast tests first: (and tests whether, say, things compile)
19-
GO111MODULE=on go test -v
19+
GO111MODULE=on go test -v ./...
2020

2121
test_gvisor: docker
2222
docker kill sandbox_front_test || true

sandbox.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ func sandboxRun(ctx context.Context, exePath string, testParam string) (sandboxt
526526
sreq.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(exeBytes)), nil }
527527
res, err := sandboxBackendClient().Do(sreq)
528528
if err != nil {
529+
if ctx.Err() == context.DeadlineExceeded {
530+
execRes.Error = "timeout running program"
531+
return execRes, nil
532+
}
529533
return execRes, fmt.Errorf("POST %q: %w", sandboxBackendURL(), err)
530534
}
531535
defer res.Body.Close()

0 commit comments

Comments
 (0)