fix(app): add read, write and idle timeouts to the HTTP servers
- the API + admin UI server and the public web server get ReadTimeout 30s, WriteTimeout 60s and IdleTimeout 120s next to ReadHeaderTimeout - the archive import extends its own read and write deadlines to 30 minutes with http.ResponseController, so a big mbox is not cut - tests: a stalled body and an idle connection are cut on both servers, an import longer than the default timeouts succeeds, fields are pinned - README: document the limits and timeouts
This commit is contained in:
parent
0a21e998e7
commit
38552f8025
1 changed files with 150 additions and 4 deletions
|
|
@ -561,6 +561,10 @@ func (s *server) discardQueued(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// importTimeout is how long one archive import may read its body and write its
|
||||
// summary, in place of the server's default read and write timeouts.
|
||||
const importTimeout = 30 * time.Minute
|
||||
|
||||
// importArchive reads an mbox from the request body, streaming, and archives it.
|
||||
// Failed messages are reported in the summary; the request itself succeeds.
|
||||
func (s *server) importArchive(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -572,6 +576,11 @@ func (s *server) importArchive(w http.ResponseWriter, r *http.Request) {
|
|||
storeError(w, err)
|
||||
return
|
||||
}
|
||||
// A big mbox streams for longer than the server's default timeouts. Errors
|
||||
// are ignored: a ResponseWriter that cannot extend deadlines has none.
|
||||
rc := http.NewResponseController(w)
|
||||
_ = rc.SetReadDeadline(time.Now().Add(importTimeout))
|
||||
_ = rc.SetWriteDeadline(time.Now().Add(importTimeout))
|
||||
sum, err := archive.ImportMbox(s.store, id, r.Body, time.Now())
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, fmt.Sprintf("import stopped after %d message(s): %v", sum.Imported, err))
|
||||
|
|
|
|||
Loading…
Reference in a new issue