apache/seatunnel · error · IllegalStateException

there should always be a valid xlog position

Error message

there should always be a valid xlog position

What it means

currentXLogLocation queries pg_current_wal_lsn (PG >= 10 / pg_is_in_recovery-aware) or pg_current_xlog_location() and uses an IllegalStateException if the ResultSet is empty. The connector assumes a valid WAL position always exists; an empty result means the server returned no row, violating that invariant.

Source

Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java:543

        return value > 0 ? value : null;
    }

    /**
     * Returns the current position in the server tx log.
     *
     * @return a long value, never negative
     * @throws SQLException if anything unexpected fails.
     */
    public long currentXLogLocation() throws SQLException {
        AtomicLong result = new AtomicLong(0);
        int majorVersion = connection().getMetaData().getDatabaseMajorVersion();
        query(
                majorVersion >= 10
                        ? "select (case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() else pg_current_wal_lsn() end) AS pg_current_wal_lsn"
                        : "select * from pg_current_xlog_location()",
                rs -> {
                    if (!rs.next()) {
                        throw new IllegalStateException(
                                "there should always be a valid xlog position");
                    }
                    result.compareAndSet(0, LogSequenceNumber.valueOf(rs.getString(1)).asLong());
                });
        return result.get();
    }

    /**
     * Returns information about the PG server to which this instance is connected.
     *
     * @return a {@link ServerInfo} instance, never {@code null}
     * @throws SQLException if anything fails
     */
    public ServerInfo serverInfo() throws SQLException {
        ServerInfo serverInfo = new ServerInfo();
        query(
                "SELECT version(), current_user, current_database()",
                rs -> {

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Verify directly on the server: SELECT pg_current_wal_lsn(); returns a row.
  2. Connect directly to the primary node rather than through a pooler/proxy that may alter queries.
  3. Confirm wal_level and server version compatibility with the connector (PG >= 10 uses pg_last_wal_receive_lsn/pg_current_wal_lsn branches).
  4. Recreate the JDBC connection / restart the connector in case of a broken session.

Example fix

// before: connection goes through an incompatible proxy
jdbc:postgresql://proxy-host:5432/db
// after: connect directly to the primary
jdbc:postgresql://primary-host:5432/db
Defensive patterns

Strategy: try-catch

Validate before calling

SELECT pg_current_wal_lsn(); -- must return one row; run before starting the connector

Try / catch

try {
    long lsn = connection.currentXLogLocation();
} catch (IllegalStateException e) {
    // reconnect directly to the primary, bypassing poolers/proxies
}

Prevention

When it happens

Trigger: The query 'select pg_current_wal_lsn...' (or pg_current_xlog_location()) returns a ResultSet with no rows — essentially only possible against a non-PostgreSQL-compatible endpoint, a broken proxy/pooler swallowing the function call, or a server function that errors into an empty result.

Common situations: Connecting through an incompatible proxy or to a read-only endpoint that rewrites queries; misrouted OpenGauss/PostgreSQL-compatible service lacking the expected catalog functions; connection state corruption mid-session.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/a28774be6e657b87. Report an issue: GitHub.