diff options
| author | Will Hawkins <[email protected]> | 2021-12-28 05:50:37 +0000 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2021-12-28 05:50:37 +0000 |
| commit | 0aa0ba75a8f17a09d3e7541cfe8c78e139299cc5 (patch) | |
| tree | db8675983d3655d4bedb72cc07fca332215f3164 | |
| parent | c6574f4232efe259f225d443df5db442fa240052 (diff) | |
Bugfix: Create new transports for each HTTP connection
By default go's network stack "helpfully" reuses the Transports
among http.Clients. This will artifically inhibit the full use
of the network. Creating new Transports for every http.Client
will keep this from happening.
| -rw-r--r-- | lbc/lbc.go | 13 | ||||
| -rw-r--r-- | networkQuality.go | 3 |
2 files changed, 10 insertions, 6 deletions
@@ -49,13 +49,14 @@ func (cr *countingReader) Read(p []byte) (n int, err error) { return 0, io.EOF } n, err = cr.readable.Read(p) - *cr.n += uint64(n) + atomic.AddUint64(cr.n, uint64(n)) return } func (lbd *LoadBearingConnectionDownload) Start(ctx context.Context, debug bool) bool { lbd.downloaded = 0 - lbd.client = &http.Client{} + transport := http.Transport{} + lbd.client = &http.Client{Transport: &transport} lbd.debug = debug lbd.valid = true @@ -91,9 +92,8 @@ func (lbd *LoadBearingConnectionDownload) doDownload(ctx context.Context) { lbd.valid = false return } - buff := make([]byte, 500*1024*1024) cr := &countingReader{n: &lbd.downloaded, ctx: ctx, readable: get.Body} - _, _ = io.CopyBuffer(ioutil.Discard, cr, buff) + _, _ = io.Copy(ioutil.Discard, cr) lbd.valid = false get.Body.Close() if lbd.debug { @@ -136,7 +136,7 @@ func (s *syntheticCountingReader) Read(p []byte) (n int, err error) { } err = nil n = len(p) - n = chunkSize + atomic.AddUint64(s.n, uint64(n)) return } @@ -156,7 +156,8 @@ func (lbu *LoadBearingConnectionUpload) doUpload(ctx context.Context) bool { func (lbu *LoadBearingConnectionUpload) Start(ctx context.Context, debug bool) bool { lbu.uploaded = 0 - lbu.client = &http.Client{} + transport := http.Transport{} + lbu.client = &http.Client{Transport: &transport} lbu.debug = debug lbu.valid = true diff --git a/networkQuality.go b/networkQuality.go index 5efbc8a..9b632e5 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -388,6 +388,9 @@ func main() { rttTimeout := false for i := 0; i < robustnessProbeIterationCount && !rttTimeout; i++ { + if len(downloadSaturation.Lbcs) == 0 { + continue + } randomLbcsIndex := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % len(downloadSaturation.Lbcs) if !downloadSaturation.Lbcs[randomLbcsIndex].IsValid() { if debug != nil { |
