Skip to content

The only tool you need to know what is happening and how to fix it.

711 B
Raw Blame
package telemetry

import (
	"context"
	"errors"
	"io"
	"net"
	"syscall"
)

// IsTransientStorageError reports failures worth retrying, so ingest can answer 503 instead of a terminal 500.
func IsTransientStorageError(err error) bool {
	if err == nil {
		return false
	}
	if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) ||
		errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, net.ErrClosed) ||
		errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.EPIPE) {
		return true
	}
	var netErr net.Error
	if errors.As(err, &netErr) && netErr.Timeout() {
		return true
	}
	return isTransientBackendError(err)
}