Skip to content

Commit bedd8ae

Browse files
committed
fix: add retry and try to fix network errors such as EOF
1 parent c27c0b9 commit bedd8ae

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pkg/httpx/httpx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewSafeClient() *http.Client {
3838
safeTransport := &http.Transport{
3939
DialContext: safeDialer.DialContext,
4040
ForceAttemptHTTP2: true,
41-
// DisableKeepAlives: true,
41+
DisableKeepAlives: true,
4242
}
4343
return &http.Client{
4444
Transport: safeTransport,

service/pull/pull.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pull
33
import (
44
"context"
55
"errors"
6+
"net"
67
"sync"
78
"time"
89

@@ -79,8 +80,17 @@ func (p *Puller) PullAll(ctx context.Context, force bool) error {
7980
<-routinePool
8081
}()
8182

83+
logger := logger.With("feed_id", f.ID)
8284
if err := p.do(ctx, f, force); err != nil {
83-
logger.Errorw(err.Error(), "feed_id", f.ID)
85+
logger.Errorln(err)
86+
if _, ok := err.(net.Error); ok {
87+
for i := 1; i < 4; i++ {
88+
logger.Infof("%dth retry", i)
89+
if p.do(ctx, f, true) == nil {
90+
break
91+
}
92+
}
93+
}
8494
}
8595
}(f)
8696
}

service/sniff/request.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func request(ctx context.Context, link string) (*http.Response, error) {
1919
return nil, err
2020
}
2121

22+
req.Close = true
23+
2224
ua := "fusion/1.0"
2325
req.Header.Add("User-Agent", ua)
2426

0 commit comments

Comments
 (0)