From 97f02e6233e8013ef904da7bce9d813c93216c3e Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 16 Mar 2022 20:54:03 -0400 Subject: Bugfix: Stop doing load-inducing downloads before RPM calculation This fix might be controversial and we will have to confirm it with the protocol designers: We will stop the actual download of the "large" file when we are about to start doing the RPM calculation. --- lbc/lbc.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lbc/lbc.go') diff --git a/lbc/lbc.go b/lbc/lbc.go index a17d1ee..01b1a4d 100644 --- a/lbc/lbc.go +++ b/lbc/lbc.go @@ -105,7 +105,6 @@ func (lbd *LoadBearingConnectionDownload) doDownload(ctx context.Context) { } cr := &countingReader{n: &lbd.downloaded, ctx: ctx, readable: get.Body} _, _ = io.Copy(ioutil.Discard, cr) - lbd.valid = false get.Body.Close() if lbd.debug { fmt.Printf("Ending a load-bearing download.\n") @@ -156,10 +155,13 @@ func (s *syntheticCountingReader) Read(p []byte) (n int, err error) { func (lbu *LoadBearingConnectionUpload) doUpload(ctx context.Context) bool { lbu.uploaded = 0 s := &syntheticCountingReader{n: &lbu.uploaded, ctx: ctx} - if resp, err := lbu.client.Post(lbu.Path, "application/octet-stream", s); err == nil { - resp.Body.Close() + var resp *http.Response = nil + var err error + + if resp, err = lbu.client.Post(lbu.Path, "application/octet-stream", s); err != nil { + lbu.valid = false } - lbu.valid = false + resp.Body.Close() if lbu.debug { fmt.Printf("Ending a load-bearing upload.\n") } -- cgit v1.2.3