Skip to content

Commit

Permalink
Apply timeouts to singleserving servers
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-soltesz committed Jun 26, 2020
1 parent 6d2e1a4 commit d133bff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ndt5/singleserving/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"sync"
"time"

ndt5metrics "github.com/m-lab/ndt-server/ndt5/metrics"
"github.com/m-lab/ndt-server/ndt5/ndt"
Expand Down Expand Up @@ -103,6 +104,12 @@ func listenWS(direction string) (*wsServer, error) {
s := &wsServer{
srv: &http.Server{
Handler: mux,
// NOTE: set absolute read and write timeouts for server connections.
// This prevents clients, or middleboxes, from opening a connection and
// holding it open indefinitely. This applies equally to TLS and non-TLS
// servers.
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
},
direction: direction,
kind: ndt.WS,
Expand Down Expand Up @@ -169,7 +176,8 @@ func (ps *plainServer) Port() int {
}

func (ps *plainServer) ServeOnce(ctx context.Context) (protocol.MeasuredConnection, error) {
derivedCtx, derivedCancel := context.WithCancel(ctx)
// NOTE: set an absolute timeouts for single serving servers.
derivedCtx, derivedCancel := context.WithTimeout(ctx, time.Minute)
defer ps.Close()

var conn net.Conn
Expand Down

0 comments on commit d133bff

Please sign in to comment.