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

Postgres connector does not support proxied connections

XMLWordPrintable

      In our application we are instrumenting our jdbc connections with opentracing to provide tracing information on jdbc activity. This tracing is accomplished by replacing the postgres jdbc connection object with a proxy that wraps it and also records the tracing information.

      There are a few places in the postgresql connector where the jdbc connection is being cast to the concrete class PgConnection. Java Proxies cannot be cast to concrete classes, but they can be cast to interfaces if they are created to implement that interface.

      Here is an example stack trace that illustrates the problem:

      java.lang.ClassCastException: com.sun.proxy.$Proxy51 cannot be cast to org.postgresql.jdbc.PgConnection
           at io.debezium.connector.postgresql.connection.PostgresConnection.determineDatabaseCharset(PostgresConnection.java:403)
           at io.debezium.connector.postgresql.connection.PostgresConnection.<init>(PostgresConnection.java:73)
           at io.debezium.connector.postgresql.PostgresConnector.validate(PostgresConnector.java:102)
           at org.apache.kafka.connect.runtime.AbstractHerder.validateConnectorConfig(AbstractHerder.java:282)
           at org.apache.kafka.connect.runtime.distributed.DistributedHerder$6.call(DistributedHerder.java:537)
           at org.apache.kafka.connect.runtime.distributed.DistributedHerder$6.call(DistributedHerder.java:534)
           at org.apache.kafka.connect.runtime.distributed.DistributedHerder.tick(DistributedHerder.java:270)
           at org.apache.kafka.connect.runtime.distributed.DistributedHerder.run(DistributedHerder.java:219)
           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:1149)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
           at java.lang.Thread.run(Thread.java:748)
      

      Looking through the code, it seems like all the places in non-test source could be cast to the interface org.postgresql.core.BaseConnection instead of PgConnection and still function the same way.

              Unassigned Unassigned
              mzbyszynski-1 Marc Zbyszynski (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: