fix: don't let a slow browser link time out the relayed speed test
This commit is contained in:
1 parent
189050b2b6
commit
6441b4329d
1 file changed
+11
-1
@@ -27,6 +27,9 @@ const (
|
|||||||
speedDownCap = 256 << 20
|
speedDownCap = 256 << 20
|
||||||
speedDownFor = 6 * time.Second
|
speedDownFor = 6 * time.Second
|
||||||
speedUpCap = 64 << 20
|
speedUpCap = 64 << 20
|
||||||
|
// speedRelayUpFor is how long the agent's upload is passed on to the
|
||||||
|
// browser: the agent's own window with slack.
|
||||||
|
speedRelayUpFor = 4 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// statCache holds the last sample per agent and serializes its refresh.
|
// statCache holds the last sample per agent and serializes its refresh.
|
||||||
@@ -364,7 +367,14 @@ func (s *Server) handleSpeedRelayUp(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, _ = io.Copy(rl.upW, http.MaxBytesReader(w, r.Body, speedUpCap))
|
body := http.MaxBytesReader(w, r.Body, speedUpCap)
|
||||||
|
// A proxy in front may hand over the whole upload at once: pass on only
|
||||||
|
// what the browser takes in the window, or the agent would wait for the
|
||||||
|
// rest to trickle through a slower link.
|
||||||
|
t := time.AfterFunc(speedRelayUpFor, func() { rl.upW.Close() })
|
||||||
|
_, _ = io.Copy(rl.upW, body)
|
||||||
|
t.Stop()
|
||||||
rl.upW.Close()
|
rl.upW.Close()
|
||||||
|
_, _ = io.Copy(io.Discard, body)
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user