{"record":{"id":"a28774be6e657b87","repo":"apache/seatunnel","slug":"there-should-always-be-a-valid-xlog-position","errorCode":null,"errorMessage":"there should always be a valid xlog position","messagePattern":"there should always be a valid xlog position","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java","lineNumber":543,"sourceCode":"        return value > 0 ? value : null;\n    }\n\n    /**\n     * Returns the current position in the server tx log.\n     *\n     * @return a long value, never negative\n     * @throws SQLException if anything unexpected fails.\n     */\n    public long currentXLogLocation() throws SQLException {\n        AtomicLong result = new AtomicLong(0);\n        int majorVersion = connection().getMetaData().getDatabaseMajorVersion();\n        query(\n                majorVersion >= 10\n                        ? \"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\"\n                        : \"select * from pg_current_xlog_location()\",\n                rs -> {\n                    if (!rs.next()) {\n                        throw new IllegalStateException(\n                                \"there should always be a valid xlog position\");\n                    }\n                    result.compareAndSet(0, LogSequenceNumber.valueOf(rs.getString(1)).asLong());\n                });\n        return result.get();\n    }\n\n    /**\n     * Returns information about the PG server to which this instance is connected.\n     *\n     * @return a {@link ServerInfo} instance, never {@code null}\n     * @throws SQLException if anything fails\n     */\n    public ServerInfo serverInfo() throws SQLException {\n        ServerInfo serverInfo = new ServerInfo();\n        query(\n                \"SELECT version(), current_user, current_database()\",\n                rs -> {","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-opengauss/src/main/java/io/debezium/connector/postgresql/connection/PostgresConnection.java#L525-L561","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify directly on the server: SELECT pg_current_wal_lsn(); returns a row.","Connect directly to the primary node rather than through a pooler/proxy that may alter queries.","Confirm wal_level and server version compatibility with the connector (PG >= 10 uses pg_last_wal_receive_lsn/pg_current_wal_lsn branches).","Recreate the JDBC connection / restart the connector in case of a broken session."],"exampleFix":"// before: connection goes through an incompatible proxy\njdbc:postgresql://proxy-host:5432/db\n// after: connect directly to the primary\njdbc:postgresql://primary-host:5432/db","handlingStrategy":"try-catch","validationCode":"SELECT pg_current_wal_lsn(); -- must return one row; run before starting the connector","typeGuard":null,"tryCatchPattern":"try {\n    long lsn = connection.currentXLogLocation();\n} catch (IllegalStateException e) {\n    // reconnect directly to the primary, bypassing poolers/proxies\n}","preventionTips":["Connect directly to the primary, not via proxies that rewrite queries.","Confirm catalog functions exist on the target (SELECT pg_current_wal_lsn()).","Test connectivity with psql before deploying the connector."],"tags":["cdc","postgres","wal","invariant"],"backgroundTag":"empty-result-set","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}