Claus Ibsen created CAMEL-27740:
-----------------------------------

             Summary: camel-pg-replication-slot: statusInterval=0 breaks polls, 
strict URI, plugin not checked
                 Key: CAMEL-27740
                 URL: https://issues.apache.org/jira/browse/CAMEL-27740
             Project: Camel
          Issue Type: Bug
          Components: camel-pg-replicationslot
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-pg-replication-slot for 
CAMEL-23832 (commit 
https://github.com/apache/camel/commit/b82eef5b59e581059179cfd3aa240e1194ec9c8c).
These are separate problems of the component; the descriptions commit only 
documents the current behavior.

h4. 1. statusInterval=0 makes every poll fail
{{PgReplicationSlotConsumer.poll()}} reads a message from the stream and then 
calls {{scheduledExecutor.scheduleAtFixedRate(..., delay, delay, 
TimeUnit.SECONDS)}} with {{delay = statusInterval}}. For a value of 0 or less 
this throws an {{IllegalArgumentException}} (the period must be positive) 
before the exchange is routed. The read payload is kept, so every following 
poll fails the same way and no message is ever routed. The PostgreSQL JDBC 
driver itself accepts 0 in {{withStatusInterval()}} and treats it as "no 
automatic status updates".
Proposed change: reject a value of 0 or less when the consumer starts, or do 
not schedule the keep-alive status updates when the value is 0.

h4. 2. The endpoint URI rejects valid database names and IPv6 hosts
{{PgReplicationSlotEndpoint.parseUri()}} matches the URI against 
{{URI_PATTERN}}, which allows only {{\w+}} (ASCII letters, digits, underscore) 
for the database and {{[^:]*}} for the host. A database such as {{my-db}} or an 
IPv6 literal such as {{[::1]}} fails with {{IllegalArgumentException: The 
provided URL does not match the acceptable pattern}}, with no hint which part 
is wrong.
Proposed change: accept the characters that PostgreSQL allows in a database 
name and bracketed IPv6 hosts, and name the part that does not match in the 
error.

h4. 3. outputPlugin is not checked against an existing slot
{{PgReplicationSlotConsumer.connect()}} uses {{outputPlugin}} only in 
{{createSlot()}}, when {{isSlotCreated()}} finds no slot of that name; 
{{getStream()}} does not use it. When the slot already exists with another 
plugin, the consumer silently delivers the format of that plugin, for example 
{{pgoutput}} binary messages on an endpoint that says {{wal2json}}. 
{{isSlotCreated()}} also matches a physical slot or a slot of another database, 
and then every poll fails when the stream starts.
Proposed change: read {{plugin}}, {{slot_type}} and {{database}} from 
{{pg_replication_slots}} at startup, and fail (or log a WARN) when they do not 
match the endpoint.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to