Commit f4f7b115 authored by Quentin Smith's avatar Quentin Smith

storage: use 60s context timeout on App Engine

Change-Id: Iaa40f3c6bf50b7351ca38ae3184431180ed71036
Reviewed-on: https://go-review.googlesource.com/35876Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent bb62666d
......@@ -19,4 +19,5 @@ func requestContext(r *http.Request) context.Context {
return appengine.NewContext(r)
}
var infof = log.Infof
var errorf = log.Errorf
......@@ -18,6 +18,8 @@ func requestContext(r *http.Request) context.Context {
return r.Context()
}
func errorf(_ context.Context, format string, args ...interface{}) {
func infof(_ context.Context, format string, args ...interface{}) {
log.Printf(format, args...)
}
var errorf = infof
......@@ -165,16 +165,19 @@ func (a *App) processUpload(ctx context.Context, user string, mr *multipart.Read
}
func (a *App) indexFile(ctx context.Context, upload *db.Upload, p io.Reader, meta map[string]string) (err error) {
fw, err := a.FS.NewWriter(ctx, fmt.Sprintf("uploads/%s.txt", meta["upload-part"]), meta)
path := fmt.Sprintf("uploads/%s.txt", meta["upload-part"])
fw, err := a.FS.NewWriter(ctx, path, meta)
if err != nil {
return err
}
defer func() {
start := time.Now()
if err != nil {
fw.CloseWithError(err)
} else {
err = fw.Close()
}
infof(ctx, "Close(%q) took %.2f seconds", path, time.Since(start).Seconds())
}()
var keys []string
for k := range meta {
......
......@@ -10,8 +10,10 @@ import (
"log"
"net/http"
"os"
"time"
_ "github.com/go-sql-driver/mysql"
"golang.org/x/net/context"
"golang.org/x/perf/storage/app"
"golang.org/x/perf/storage/db"
"golang.org/x/perf/storage/fs/gcs"
......@@ -69,6 +71,13 @@ func auth(w http.ResponseWriter, r *http.Request) (string, error) {
// be supplied in /upload responses.
func appHandler(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
// App Engine does not return a context with a deadline set,
// even though the request does have a deadline. urlfetch uses
// a 5s default timeout if the context does not have a
// deadline, so explicitly set a deadline to match the App
// Engine timeout.
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
// GCS clients need to be constructed with an AppEngine
// context, so we can't actually make the App until the
// request comes in.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment