Skip to content

Commit b8c0e2b

Browse files
committed
playground: only build binaries for health check
This change avoids cascading sandbox backend failures to the frontend instances. The timeout TODO is safe to remove as we now pass in the request context for cancellation, and sandboxBuild has its own build timeout. Updates golang/go#25224 Updates golang/go#38530 Change-Id: If892f86bad08c55429b6ebab768b83c5d7621cf1 Reviewed-on: https://go-review.googlesource.com/c/playground/+/229677 Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 11cd822 commit b8c0e2b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

sandbox.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,20 @@ func playgroundGoproxy() string {
593593
return "https://proxy.golang.org"
594594
}
595595

596-
func (s *server) healthCheck() error {
597-
ctx := context.Background() // TODO: cap it to some reasonable timeout
598-
resp, err := compileAndRun(ctx, &request{Body: healthProg})
596+
// healthCheck attempts to build a binary from the source in healthProg.
597+
// It returns any error returned from sandboxBuild, or nil if none is returned.
598+
func (s *server) healthCheck(ctx context.Context) error {
599+
tmpDir, err := ioutil.TempDir("", "sandbox")
599600
if err != nil {
600-
return err
601+
return fmt.Errorf("error creating temp directory: %v", err)
601602
}
602-
if resp.Errors != "" {
603-
return fmt.Errorf("compile error: %v", resp.Errors)
603+
defer os.RemoveAll(tmpDir)
604+
br, err := sandboxBuild(ctx, tmpDir, []byte(healthProg), false)
605+
if err != nil {
606+
return err
604607
}
605-
if len(resp.Events) != 1 || resp.Events[0].Message != "ok" {
606-
return fmt.Errorf("unexpected output: %v", resp.Events)
608+
if br.errorMessage != "" {
609+
return errors.New(br.errorMessage)
607610
}
608611
return nil
609612
}

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func handleFavicon(w http.ResponseWriter, r *http.Request) {
7575
}
7676

7777
func (s *server) handleHealthCheck(w http.ResponseWriter, r *http.Request) {
78-
if err := s.healthCheck(); err != nil {
78+
if err := s.healthCheck(r.Context()); err != nil {
7979
http.Error(w, "Health check failed: "+err.Error(), http.StatusInternalServerError)
8080
return
8181
}

tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *server) test() {
3737
}
3838

3939
func (s *server) runTests() {
40-
if err := s.healthCheck(); err != nil {
40+
if err := s.healthCheck(context.Background()); err != nil {
4141
stdlog.Fatal(err)
4242
}
4343

0 commit comments

Comments
 (0)