Skip to content

Commit 7bc88b3

Browse files
committed
add: new known error
1 parent cca3cb0 commit 7bc88b3

5 files changed

Lines changed: 48 additions & 25 deletions

File tree

db/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var KnownErrors = map[string]string{
3535
"can't assign requested address": models.NetErrorCantAssignRequestedAddress, // transient error
3636
"cannot assign requested address": models.NetErrorCantAssignRequestedAddress, // transient error
3737
"connection gated": models.NetErrorConnectionGated, // transient error
38+
"connection closed immediately": models.NetErrorConnectionClosedImmediately,
3839
}
3940

4041
var ErrorStr = map[string]string{}
@@ -74,6 +75,7 @@ var knownErrorsPrecedence = []string{
7475
"failed to negotiate stream multiplexer",
7576
"resource limit exceeded",
7677
"Write on stream",
78+
"connection closed immediately",
7779
}
7880

7981
// NetError extracts the appropriate error type from the given error.

db/migrations/000026_add_net_errors.up.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ BEGIN;
33
ALTER TYPE net_error ADD VALUE 'connection_reset_by_peer';
44
ALTER TYPE net_error ADD VALUE 'cant_assign_requested_address';
55
ALTER TYPE net_error ADD VALUE 'connection_gated';
6+
ALTER TYPE net_error ADD VALUE 'connection_closed_immediately';
67
ALTER TYPE net_error RENAME VALUE 'no_public_ip' TO 'no_ip_address';
78

89
CREATE OR REPLACE FUNCTION calc_max_failed_visits(

db/models/boil_types.go

Lines changed: 24 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

discv5/crawler.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/p2p/enode"
1212
"github.com/friendsofgo/errors"
13+
"github.com/libp2p/go-libp2p/core/network"
1314
"github.com/libp2p/go-libp2p/core/peer"
1415
"github.com/libp2p/go-libp2p/p2p/host/basic"
1516
ma "github.com/multiformats/go-multiaddr"
@@ -211,26 +212,43 @@ func (c *Crawler) connect(ctx context.Context, pi peer.AddrInfo) error {
211212
}
212213

213214
retry := 0
214-
maxRetries := 1
215+
maxRetries := 2
215216
for {
217+
216218
timeout := time.Duration(c.cfg.DialTimeout.Nanoseconds() / int64(retry+1))
219+
220+
logEntry := log.WithFields(log.Fields{
221+
"timeout": timeout.String(),
222+
"remoteID": dialAddrInfo.ID.String(),
223+
"retry": retry,
224+
"maddrs": dialAddrInfo.Addrs,
225+
})
226+
logEntry.Debugln("Connecting to peer", dialAddrInfo.ID.ShortString())
227+
217228
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
218229
err := c.host.Connect(timeoutCtx, dialAddrInfo)
219230
cancel()
220231

221232
if err == nil {
222-
return nil
233+
if c.host.Network().Connectedness(pi.ID) != network.Connected {
234+
err = fmt.Errorf("connection closed immediately")
235+
} else {
236+
return nil
237+
}
223238
}
224239

225240
switch true {
226241
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorNegotiateSecurityProtocol]):
227242
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorConnectionRefused]):
228243
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorConnectionResetByPeer]):
244+
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorConnectionClosedImmediately]):
229245
default:
246+
logEntry.WithError(err).Debugln("Failed connecting to peer", dialAddrInfo.ID.ShortString())
230247
return err
231248
}
232249

233250
if retry == maxRetries {
251+
logEntry.WithError(err).Debugln("Exceeded retries connecting to peer", dialAddrInfo.ID.ShortString())
234252
return err
235253
}
236254

discv5/driver_crawler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (p PeerInfo) Addrs() []ma.Multiaddr {
107107

108108
func (p PeerInfo) Merge(other PeerInfo) PeerInfo {
109109
p.maddrs = utils.MergeMaddrs(p.maddrs, other.maddrs)
110-
return p // TODO: merge
110+
return p
111111
}
112112

113113
type CrawlDriverConfig struct {

0 commit comments

Comments
 (0)