Skip to content

Commit 820c069

Browse files
committed
feat(): fix concurrent get chunks bug
1 parent 4714928 commit 820c069

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

client.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,13 @@ func (c *Client) ConcurrentDownloadChunkData(id string, concurrentNum int) ([]by
596596
chunkData, err := c.getChunkData(oss.Offset)
597597
if err != nil {
598598
count := 0
599-
for count < 3 {
600-
time.Sleep(2 * time.Second)
599+
for count < 2 {
600+
time.Sleep(1 * time.Second)
601601
chunkData, err = c.getChunkData(oss.Offset)
602602
if err == nil {
603603
break
604604
}
605-
log.Error("retry getChunkData failed and try again...", "err", err, "offset", oss.Offset, "retryCount", count, "arId", id)
605+
log.Error("retry getChunkData failed and try again...", "err", err, "idx", oss.Idx, "offset", oss.Offset, "retryCount", count, "arId", id)
606606
if err != ErrRequestLimit {
607607
count++
608608
}
@@ -630,18 +630,21 @@ func (c *Client) ConcurrentDownloadChunkData(id string, concurrentNum int) ([]by
630630
chunkData, err := c.getChunkData(int64(i) + start)
631631
if err != nil {
632632
count := 0
633-
for count < 3 {
634-
time.Sleep(2 * time.Second)
633+
for count < 2 {
634+
time.Sleep(1 * time.Second)
635635
chunkData, err = c.getChunkData(int64(i) + start)
636636
if err == nil {
637637
break
638638
}
639-
log.Error("retry getChunkData failed and try again...", "err", err, "offset", int64(i)+start, "retryCount", count, "arId", id)
639+
log.Error("latest two chunks retry getChunkData failed and try again...", "err", err, "offset", int64(i)+start, "retryCount", count, "arId", id)
640640
if err != ErrRequestLimit {
641641
count++
642642
}
643643
}
644644
}
645+
if err != nil {
646+
return nil, errors.New("concurrent get latest two chunks failed")
647+
}
645648
chunkArr = append(chunkArr, chunkData)
646649
i += len(chunkData)
647650
}

client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func TestClient_GetBlockHashList2(t *testing.T) {
309309

310310
func TestClient_ConcurrentDownloadChunkData(t *testing.T) {
311311
c := NewClient("https://arweave.net")
312-
arId := "6G_gCR5ZlFzg5Ek3DDTgwFFJhOKEowKJjHaA6Bt48VA"
312+
arId := "trMxnk1aVVb_Nafg18tstoLS6SvUOpNcoSQ2qFazWio"
313313
data, err := c.ConcurrentDownloadChunkData(arId, 0)
314314
// data , err := c.DownloadChunkData(arId)
315315
assert.NoError(t, err)
@@ -322,7 +322,7 @@ func TestClient_ConcurrentDownloadChunkData(t *testing.T) {
322322

323323
func TestClient_ExistTxData(t *testing.T) {
324324
c := NewClient("https://arweave.net")
325-
arId := "cAC7ave2lo3aixlC1wdvRBpGa3ELX_s2M2zJ03u0AwI"
325+
arId := "trMxnk1aVVb_Nafg18tstoLS6SvUOpNcoSQ2qFazWio"
326326
exist, err := c.ExistTxData(arId)
327327
assert.NoError(t, err)
328328
t.Log(exist)

0 commit comments

Comments
 (0)