Skip to content

Commit e610e55

Browse files
committed
add relay connection error case
1 parent 450725a commit e610e55

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

db/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ 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+
"RESOURCE_LIMIT_EXCEEDED (201)": models.NetErrorCantConnectOverRelay, // transient error
39+
"NO_RESERVATION (204)": models.NetErrorCantConnectOverRelay, // permanent error
3840
}
3941

4042
var ErrorStr = map[string]string{}
@@ -74,6 +76,8 @@ var knownErrorsPrecedence = []string{
7476
"failed to negotiate stream multiplexer",
7577
"resource limit exceeded",
7678
"Write on stream",
79+
"RESOURCE_LIMIT_EXCEEDED (201)",
80+
"NO_RESERVATION (204)",
7781
}
7882

7983
// 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 'cant_connect_over_relay';
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: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libp2p/crawler_p2p.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (c *Crawler) connect(ctx context.Context, pi peer.AddrInfo) error {
144144

145145
var (
146146
retry int = 0
147-
maxRetries int = 2
147+
maxRetries int = 3
148148
firstErr error = nil
149149
)
150150

@@ -177,8 +177,15 @@ func (c *Crawler) connect(ctx context.Context, pi peer.AddrInfo) error {
177177

178178
switch true {
179179
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorConnectionRefused]):
180+
// Might be transient because the remote doesn't want us to connect. Try again!
180181
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorConnectionGated]):
182+
// Hints at a configuration issue but could be transient. Try again!
181183
case strings.Contains(err.Error(), db.ErrorStr[models.NetErrorCantAssignRequestedAddress]):
184+
// Transient error due to local UDP issues. Try again!
185+
maxRetries = 10 // increase the maximum number of retries as the error _should_ go away
186+
case strings.Contains(err.Error(), db.ErrorStr["RESOURCE_LIMIT_EXCEEDED (201)"]): // thrown by a circuit relay
187+
// We already have too many open connections over a relay. Try again!
188+
maxRetries = 10 // increase the maximum number of retries as the error _should_ go away
182189
default:
183190
if errors.Is(err, context.DeadlineExceeded) {
184191
err = firstErr

0 commit comments

Comments
 (0)