Add HTTP 504 request timeouts to certain routes
This commit is contained in:
parent
a96a8466cb
commit
a133eb2482
3 changed files with 31 additions and 2 deletions
15
db/db.go
15
db/db.go
|
@ -183,8 +183,16 @@ func Process(ctx *fibre.Context, ast *sql.Query, vars map[string]interface{}) (o
|
|||
// return results, buffer the output, and
|
||||
// return the output when finished.
|
||||
|
||||
for res := range recv {
|
||||
out = append(out, res)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Context().Done():
|
||||
return nil, fibre.NewHTTPError(504)
|
||||
case res, open := <-recv:
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
out = append(out, res)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -236,6 +244,9 @@ func (e *executor) execute(ctx context.Context, quit <-chan bool, send chan<- *R
|
|||
|
||||
select {
|
||||
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case <-quit:
|
||||
return
|
||||
|
||||
|
|
|
@ -142,4 +142,10 @@ var errs = map[int]*err{
|
|||
Details: "Not Implemented",
|
||||
Description: "The server either does not recognize the request method, or it lacks the ability to fulfill the request.",
|
||||
},
|
||||
|
||||
504: {
|
||||
Code: 504,
|
||||
Details: "Gateway Timeout",
|
||||
Description: "The request to the server was restricted by a timeout duration, and did not manage to complete in time.",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -84,6 +84,10 @@ func routes(s *fibre.Fibre) {
|
|||
return signup(c)
|
||||
})
|
||||
|
||||
s.Use(mw.Quit(&mw.QuitOpts{
|
||||
Timeout: 10 * time.Second,
|
||||
}).PathIs("/signup"))
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
|
@ -105,6 +109,10 @@ func routes(s *fibre.Fibre) {
|
|||
return signin(c)
|
||||
})
|
||||
|
||||
s.Use(mw.Quit(&mw.QuitOpts{
|
||||
Timeout: 10 * time.Second,
|
||||
}).PathIs("/signin"))
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
|
@ -336,6 +344,10 @@ func routes(s *fibre.Fibre) {
|
|||
|
||||
})
|
||||
|
||||
s.Use(mw.Quit(&mw.QuitOpts{
|
||||
Timeout: 15 * time.Second,
|
||||
}).PathBegsWith("/key/"))
|
||||
|
||||
s.Use(mw.Type(&mw.TypeOpts{
|
||||
AllowedContent: map[string]bool{
|
||||
"application/json": true,
|
||||
|
|
Loading…
Reference in a new issue