GH-9597: Fix Mqttv5PahoMessageHandler.publish() for concurrency
Fixes: #9597
Issue link: https://github.com/spring-projects/spring-integration/issues/9597
When input channel for the endpoint with a `Mqttv5PahoMessageHandler` is an `ExecutorChannel` and a lot of concurrent messages are sent,
the `Connect already in progress (32110)` exception can be thrown
* Wrap `this.mqttClient.connect()` in the `Mqttv5PahoMessageHandler.publish()` into a `Lock`
(cherry picked from commit 334620f36e)
This commit is contained in:
committed by
Spring Builds
parent
44d035fcaa
commit
fb6e6c63df
@@ -266,7 +266,15 @@ public class Mqttv5PahoMessageHandler extends AbstractMqttMessageHandler<IMqttAs
|
||||
long completionTimeout = getCompletionTimeout();
|
||||
try {
|
||||
if (!this.mqttClient.isConnected()) {
|
||||
this.mqttClient.connect(this.connectionOptions).waitForCompletion(completionTimeout);
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (!this.mqttClient.isConnected()) {
|
||||
this.mqttClient.connect(this.connectionOptions).waitForCompletion(completionTimeout);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
IMqttToken token = this.mqttClient.publish(topic, (MqttMessage) mqttMessage);
|
||||
ApplicationEventPublisher applicationEventPublisher = getApplicationEventPublisher();
|
||||
|
||||
Reference in New Issue
Block a user