Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-699

PostgresReplicationConnection doesn't close jdbc connection

    XMLWordPrintable

Details

    • Hide
      1. Create postgresql-connector by the following command:
        curl -i -X POST -H "Accept:application/json" -H  "Content-Type:application/json" http://localhost:8083/connectors/ -d'
        {
          "name": "postgresql-connector",
          "config": {
            "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
            "database.hostname": "postgresql",
            "database.port": "5432",
            "database.user": "postgres",
            "database.password": "postgres",
            "database.dbname": "postgres",
            "slot.name": "debezium-",
            "database.server.name": "test"
          }
        }'
        
      2. Make sure the log contains the following exception:
        [2018-05-21T15:43:56,108][ERROR][category=org.apache.kafka.connect.runtime.WorkerTask] Task postgresql-connector-0 threw an uncaught and unrecoverable exception
        io.debezium.jdbc.JdbcConnectionException: ERROR: syntax error: unexpected character "-"
        	at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initReplicationSlot(PostgresReplicationConnection.java:136)
        	at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.<init>(PostgresReplicationConnection.java:79)
        	at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.<init>(PostgresReplicationConnection.java:38)
        	at io.debezium.connector.postgresql.connection.PostgresReplicationConnection$ReplicationConnectionBuilder.build(PostgresReplicationConnection.java:349)
        	at io.debezium.connector.postgresql.PostgresTaskContext.createReplicationConnection(PostgresTaskContext.java:63)
        	at io.debezium.connector.postgresql.RecordsStreamProducer.<init>(RecordsStreamProducer.java:75)
        	at io.debezium.connector.postgresql.RecordsSnapshotProducer.<init>(RecordsSnapshotProducer.java:70)
        	at io.debezium.connector.postgresql.PostgresConnectorTask.createSnapshotProducer(PostgresConnectorTask.java:131)
        	at io.debezium.connector.postgresql.PostgresConnectorTask.start(PostgresConnectorTask.java:84)
        	at io.debezium.connector.common.BaseSourceTask.start(BaseSourceTask.java:45)
        	at org.apache.kafka.connect.runtime.WorkerSourceTask.execute(WorkerSourceTask.java:142)
        	at org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:146)
        	at org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:190)
        	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        	at java.lang.Thread.run(Thread.java:745)
        Caused by: org.postgresql.util.PSQLException: ERROR: syntax error: unexpected character "-"
        	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
        	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
        	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
        	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
        	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
        	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
        	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
        	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
        	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)
        	at org.postgresql.replication.fluent.logical.LogicalCreateSlotBuilder.make(LogicalCreateSlotBuilder.java:48)
        	at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initReplicationSlot(PostgresReplicationConnection.java:102)
        	... 17 more
        

      AR: The pg_stat_replication view contains row with startup state:

      select * from pg_stat_replication where state = 'startup';
      
       pid  | usesysid |  usename   |    application_name    | client_addr  | client_hostname | client_port |         backend_start         | backend_xmin |   state   | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state
      ------+----------+------------+------------------------+--------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
       5142 |       10 | postgres   | PostgreSQL JDBC Driver | 172.20.0.7   |                 |       36032 | 2018-05-22 08:32:57.731659+00 |              | startup   |               |                |                |                 |             0 | async
      
      Show
      Create postgresql-connector by the following command: curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d' { "name": "postgresql-connector", "config": { "connector.class": "io.debezium.connector.postgresql.PostgresConnector", "database.hostname": "postgresql", "database.port": "5432", "database.user": "postgres", "database.password": "postgres", "database.dbname": "postgres", "slot.name": "debezium-", "database.server.name": "test" } }' Make sure the log contains the following exception: [2018-05-21T15:43:56,108][ERROR][category=org.apache.kafka.connect.runtime.WorkerTask] Task postgresql-connector-0 threw an uncaught and unrecoverable exception io.debezium.jdbc.JdbcConnectionException: ERROR: syntax error: unexpected character "-" at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initReplicationSlot(PostgresReplicationConnection.java:136) at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.<init>(PostgresReplicationConnection.java:79) at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.<init>(PostgresReplicationConnection.java:38) at io.debezium.connector.postgresql.connection.PostgresReplicationConnection$ReplicationConnectionBuilder.build(PostgresReplicationConnection.java:349) at io.debezium.connector.postgresql.PostgresTaskContext.createReplicationConnection(PostgresTaskContext.java:63) at io.debezium.connector.postgresql.RecordsStreamProducer.<init>(RecordsStreamProducer.java:75) at io.debezium.connector.postgresql.RecordsSnapshotProducer.<init>(RecordsSnapshotProducer.java:70) at io.debezium.connector.postgresql.PostgresConnectorTask.createSnapshotProducer(PostgresConnectorTask.java:131) at io.debezium.connector.postgresql.PostgresConnectorTask.start(PostgresConnectorTask.java:84) at io.debezium.connector.common.BaseSourceTask.start(BaseSourceTask.java:45) at org.apache.kafka.connect.runtime.WorkerSourceTask.execute(WorkerSourceTask.java:142) at org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:146) at org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:190) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.postgresql.util.PSQLException: ERROR: syntax error: unexpected character "-" at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301) at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260) at org.postgresql.replication.fluent.logical.LogicalCreateSlotBuilder.make(LogicalCreateSlotBuilder.java:48) at io.debezium.connector.postgresql.connection.PostgresReplicationConnection.initReplicationSlot(PostgresReplicationConnection.java:102) ... 17 more AR: The pg_stat_replication view contains row with startup state: select * from pg_stat_replication where state = 'startup' ; pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state ------+----------+------------+------------------------+--------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------ 5142 | 10 | postgres | PostgreSQL JDBC Driver | 172.20.0.7 | | 36032 | 2018-05-22 08:32:57.731659+00 | | startup | | | | | 0 | async

    Description

      PostgresReplicationConnection doesn't close jdbc connection if an exception is thrown during class instantiation:

      private PostgresReplicationConnection(Configuration config,
                                           String slotName,
                                           PostgresConnectorConfig.LogicalDecoder plugin,
                                           boolean dropSlotOnClose,
                                           Integer statusUpdateIntervalMillis,
                                           TypeRegistry typeRegistry) {
          ...
      
          try {
              initReplicationSlot();
          } catch (SQLException e) {
              throw new JdbcConnectionException("Cannot create replication connection", e);
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              jpechane Jiri Pechanec
              andrey.pustovetov@gmail.com Andrey Pustovetov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: