allthingssecurity commented on code in PR #27693:
URL: https://github.com/apache/camel/pull/27693#discussion_r4245775014
##########
components/camel-pgevent/src/main/java/org/apache/camel/component/pgevent/PgEventConsumer.java:
##########
@@ -102,15 +107,20 @@ public class PgEventListener implements
PGNotificationListener {
public void reconnect() {
// only submit the task if not already running
- if (!reconnectTask.isRunning()) {
- reconnectTask.run(endpoint.getCamelContext(), () -> {
+ BackgroundTask current = reconnectTask;
+ if (current == null || !current.isRunning()) {
+ // a background task completes only once (running it again
does nothing), so every reconnect needs
+ // its own task
+ final BackgroundTask task = createReconnectTask();
+ reconnectTask = task;
+ task.run(endpoint.getCamelContext(), () -> {
if (isRunAllowed()) {
- LOG.debug("Connecting attempt #{}",
reconnectTask.iteration());
+ LOG.debug("Connecting attempt #{}", task.iteration());
try {
initConnection();
Review Comment:
Fixed in 41196072ddb6. `initConnection()` closes the connection it replaces
before it opens the new one, and a
connection whose `LISTEN` (or adding the listener) fails is closed before
the attempt fails. `closeConnection()`
also skipped `close()` when `UNLISTEN` failed, which it does on a lost
connection; it now closes in a `finally`.
The listener is removed from a connection before it is closed. Tests with
the mocked `DataSource`:
`closesTheLostConnectionWhenItReconnects` and
`closesAConnectionWhoseListenFails`; both fail on the previous commit.
_Claude Code on behalf of allthingssecurity_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]