Skip to content

Commit 661c196

Browse files
authored
explicit check for "use of closed network connection" suffix (#3408)
many libraries create this error themselves, & check this way, as historically go did not expose net.ErrClosed type
1 parent 7c7cd7a commit 661c196

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

flow/alerting/alerting.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ func (a *Alerter) logFlowErrorInternal(
454454
) {
455455
logger := internal.LoggerFromCtx(ctx)
456456
inErrWithStack := fmt.Sprintf("%+v", inErr)
457-
loggerFunc(inErr.Error(), slog.String("stack", inErrWithStack))
457+
errError := inErr.Error()
458+
loggerFunc(errError, slog.String("stack", inErrWithStack))
458459
if _, err := a.CatalogPool.Exec(
459460
ctx, "INSERT INTO peerdb_stats.flow_errors(flow_name,error_message,error_type) VALUES($1,$2,$3)",
460461
flowName, inErrWithStack, errorType.String(),
@@ -470,7 +471,7 @@ func (a *Alerter) logFlowErrorInternal(
470471
if errors.Is(inErr, io.EOF) || errors.Is(inErr, io.ErrUnexpectedEOF) {
471472
tags = append(tags, string(shared.ErrTypeEOF))
472473
}
473-
if errors.Is(inErr, net.ErrClosed) {
474+
if errors.Is(inErr, net.ErrClosed) || strings.HasSuffix(errError, "use of closed network connection") {
474475
tags = append(tags, string(shared.ErrTypeClosed))
475476
}
476477
var pgErr *pgconn.PgError
@@ -502,7 +503,7 @@ func (a *Alerter) logFlowErrorInternal(
502503
if internal.PeerDBTelemetrySenderSendErrorAlertsEnabled() {
503504
a.sendTelemetryMessage(ctx, logger, flowName, inErrWithStack, telemetry.ERROR, tags...)
504505
}
505-
loggerFunc(fmt.Sprintf("Emitting error/warning metric: '%s'", inErr.Error()),
506+
loggerFunc(fmt.Sprintf("Emitting error/warning metric: '%s'", errError),
506507
slog.Any("error", inErr),
507508
slog.Any("errorClass", errorClass),
508509
slog.Any("errorInfo", errInfo),

flow/alerting/classifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func GetErrorClass(ctx context.Context, err error) (ErrorClass, ErrorInfo) {
539539
}
540540
}
541541

542-
if errors.Is(err, net.ErrClosed) {
542+
if errors.Is(err, net.ErrClosed) || strings.HasSuffix(err.Error(), "use of closed network connection") {
543543
return ErrorIgnoreConnTemporary, ErrorInfo{
544544
Source: ErrorSourceNet,
545545
Code: "net.ErrClosed",

0 commit comments

Comments
 (0)