summaryrefslogtreecommitdiff
path: root/lbc/lbc.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2021-12-28 05:50:37 +0000
committerWill Hawkins <[email protected]>2021-12-28 05:50:37 +0000
commit0aa0ba75a8f17a09d3e7541cfe8c78e139299cc5 (patch)
treedb8675983d3655d4bedb72cc07fca332215f3164 /lbc/lbc.go
parentc6574f4232efe259f225d443df5db442fa240052 (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.
Diffstat (limited to 'lbc/lbc.go')
-rw-r--r--lbc/lbc.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/lbc/lbc.go b/lbc/lbc.go
index 5cfcf9f..17dfe7b 100644
--- a/lbc/lbc.go
+++ b/lbc/lbc.go
@@ -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