Fix PostgresSubscribableChannel.notifyUpdate()
When transaction is configured for the `PostgresSubscribableChannel.notifyUpdate()` and it is rolled back, the next poll in that loop will return the same message. Again and again if transaction is always rolled back. This leads to the condition when we never leave this loop even if we fully unsubscribed from this channel. The issue has need spotted after introducing `SKIP LOCKED` for `PostgresChannelMessageStoreQueryProvider` which leads to the locked record in DB in the mentioned above transaction. * Introduce `PostgresSubscribableChannel.hasHandlers` flag to check in the `notifyUpdate()` before performing poll query in DB. **Cherry-pick to `6.1.x` & `6.0.x`**
This commit is contained in:
@@ -45,6 +45,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -172,14 +173,16 @@ public class PostgresChannelMessageTableSubscriberTests implements PostgresConta
|
||||
postgresSubscribableChannel.setTransactionManager(transactionManager);
|
||||
|
||||
postgresChannelMessageTableSubscriber.start();
|
||||
postgresSubscribableChannel.subscribe(message -> {
|
||||
MessageHandler messageHandler =
|
||||
message -> {
|
||||
try {
|
||||
throw new RuntimeException("An error has occurred");
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
};
|
||||
postgresSubscribableChannel.subscribe(messageHandler);
|
||||
|
||||
messageStore.addMessageToGroup(groupId, new GenericMessage<>("1"));
|
||||
messageStore.addMessageToGroup(groupId, new GenericMessage<>("2"));
|
||||
@@ -188,6 +191,7 @@ public class PostgresChannelMessageTableSubscriberTests implements PostgresConta
|
||||
|
||||
// Stop subscriber to unlock records from TX for the next verification
|
||||
postgresChannelMessageTableSubscriber.stop();
|
||||
postgresSubscribableChannel.unsubscribe(messageHandler);
|
||||
|
||||
assertThat(messageStore.messageGroupSize(groupId)).isEqualTo(2);
|
||||
assertThat(messageStore.pollMessageFromGroup(groupId).getPayload()).isEqualTo("1");
|
||||
|
||||
Reference in New Issue
Block a user