Module eysql_error

Sort epgsql errors into what a caller can do about them.

Description

Sort epgsql errors into what a caller can do about them.

retryable: the statement or transaction failed and nothing was committed; run it again (serialization failure 40001, deadlock 40P01). YugabyteDB reports its transaction conflicts and read restarts as 40001.

connection_lost: the connection is gone (server shutdown 57P0x, any class 08 connection exception, or a closed socket). Work in an open transaction was not committed; a COMMIT in flight has an unknown outcome.

other: anything else, such as a constraint violation or bad SQL.

connect_failure/1 sorts the errors of a failed connect instead: whether the host could not be reached at all, which leaves it out of new connections, or answered and turned the connection away.

Data Types

class()

class() = retryable | connection_lost | other

connect_failure()

connect_failure() = unreachable | rejected

Function Index

classify/1
code/1The SQLSTATE of a server error, or undefined.
connect_failure/1Why a connect failed, as the JDBC smart driver sorts it.
is_connection_lost/1
is_retryable/1

Function Details

classify/1

classify(Error::term()) -> class()

code/1

code(Error::term()) -> binary() | undefined

The SQLSTATE of a server error, or undefined.

connect_failure/1

connect_failure(Error::term()) -> connect_failure()

Why a connect failed, as the JDBC smart driver sorts it.

unreachable: no connection could be made to the host. These are the failures pgjdbc reports as SQLSTATE 08001, CONNECTION_UNABLE_TO_CONNECT, the only ones after which the smart driver marks a host down (LoadBalanceService.getConnection). ConnectionFactoryImpl.openConnectionImpl gives that state to every I/O failure while connecting: a refused or timed-out TCP connect, a name that does not resolve, no route, and a connection that drops before the session is ready. In epgsql and OTP terms:

rejected: anything else. The server answered, and the connection failed all the same: a failed login (invalid_password, 28P01, or invalid_authorization_specification, 28000), a missing database (3D000), too many connections (53300), a server starting up or shutting down (57P03), any other server error, an authentication method epgsql does not support, a server without TLS under ssl => required (ssl_not_available, 08004 in pgjdbc), and a failed TLS handshake ({ssl_negotiation_failed, _}, which pgjdbc's MakeSSL.convert reports as 08006, CONNECTION_FAILURE, whatever the cause). pgjdbc skips such a host for the rest of that one connection and does not mark it down.

is_connection_lost/1

is_connection_lost(Error::term()) -> boolean()

is_retryable/1

is_retryable(Error::term()) -> boolean()


Generated by EDoc