Skip to content

Commit 38bb49e

Browse files
authored
Merge pull request #1765 from 0chain/fix/http-client
Fix http client
2 parents 49c9b60 + 4c947d2 commit 38bb49e

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

zboxcore/sdk/commitworker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,15 @@ func (commitReq *CommitRequestV2) processCommit() {
460460
} else if resp.err != errAlreadySuccessful {
461461
commitReq.commitMask = commitReq.commitMask.And(zboxutil.NewUint128(1).Lsh(resp.pos).Not())
462462
if commitReq.commitMask.CountOnes() < commitReq.consensusThresh {
463+
commitReq.commitMask = zboxutil.NewUint128(0)
463464
commitReq.result = ErrorCommitResult("Failed to get reference path " + resp.err.Error())
464465
return
465466
}
466467
}
467468
}
468469

469470
if trie == nil {
471+
commitReq.commitMask = zboxutil.NewUint128(0)
470472
commitReq.result = ErrorCommitResult("Failed to get reference path")
471473
return
472474
}

zboxcore/sdk/downloadworker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ func (req *DownloadRequest) processDownload() {
626626

627627
totalWritten, err := writeData(req.fileHandler, data, req.datashards, int(remainingSize))
628628
if err != nil {
629+
l.Logger.Error("Write failed: ", err, " path: ", req.remotefilepath)
629630
req.errorCB(errors.Wrap(err, "Write file failed"), remotePathCB)
630631
return
631632
}

zboxcore/sdk/multi_operation_worker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,18 @@ func (mo *MultiOperation) commitV2() error {
413413
} else {
414414
changes = mo.changesV2
415415
}
416+
threshold := mo.consensusThresh
417+
if mask.CountOnes() < mo.consensusThresh {
418+
threshold = mask.CountOnes()
419+
}
416420
commitReq := &CommitRequestV2{
417421
allocationObj: mo.allocationObj,
418422
connectionID: mo.connectionID,
419423
sig: mo.allocationObj.sig,
420424
wg: wg,
421425
timestamp: timestamp,
422426
commitMask: mask,
423-
consensusThresh: mo.consensusThresh,
427+
consensusThresh: threshold,
424428
changes: changes,
425429
isRepair: mo.isRepair,
426430
}

zboxcore/zboxutil/download_buffer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (r *DownloadBufferWithChan) RequestChunk(ctx context.Context, num int) []by
5757
return nil
5858
case ind := <-r.ch:
5959
r.mu.Lock()
60+
if r.mp == nil {
61+
r.mu.Unlock()
62+
return nil
63+
}
6064
r.mp[num] = ind
6165
r.mu.Unlock()
6266
return r.buf[ind*r.reqSize : (ind+1)*r.reqSize : (ind+1)*r.reqSize]

zboxcore/zboxutil/http.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package zboxutil
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
67
"encoding/json"
78
"io"
89
"net"
@@ -150,7 +151,22 @@ var envProxy proxyFromEnv
150151

151152
func init() {
152153
Client = &http.Client{
153-
Transport: http.DefaultTransport,
154+
Transport: &http.Transport{
155+
TLSClientConfig: &tls.Config{
156+
InsecureSkipVerify: false,
157+
MinVersion: tls.VersionTLS12,
158+
SessionTicketsDisabled: false, // Enable TLS session reuse
159+
},
160+
DialContext: (&net.Dialer{
161+
Timeout: 30 * time.Second,
162+
KeepAlive: 45 * time.Second,
163+
}).DialContext,
164+
MaxIdleConns: 500,
165+
MaxIdleConnsPerHost: 100,
166+
IdleConnTimeout: 45 * time.Second,
167+
DisableKeepAlives: false,
168+
ForceAttemptHTTP2: true,
169+
},
154170
}
155171

156172
FastHttpClient = &fasthttp.Client{

0 commit comments

Comments
 (0)