turcsanyip commented on code in PR #11804:
URL: https://github.com/apache/nifi/pull/11804#discussion_r4669742304
##########
nifi-extension-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/adapters/HiveMqV5ClientAdapter.java:
##########
@@ -157,7 +148,21 @@ public void
setReceivedMessageHandler(ReceivedMqttMessageHandler handler) {
});
}
- private static Mqtt5BlockingClient createClient(URI brokerUri,
MqttClientProperties clientProperties, ComponentLog logger) throws TlsException
{
+ private <T> T awaitWithTimeout(Future<T> future) {
+ try {
+ final T response =
future.get(clientProperties.getConnectionTimeout(), TimeUnit.SECONDS);
+ logger.debug("Received response: {}", response);
+ return response;
+ } catch (Exception e) {
+ future.cancel(true);
Review Comment:
Further investigation revealed that neither `future.cancel(true)` nor
`disconnect()` can abort and clean up the pending connection request properly:
- `cancel()` only interrupts the waiting thread but not the ongoing request
- `disconnect()` can handle established connections only, otherwise it
throws an exception
The HiveMQ client has `mqttConnectTimeout` configuration parameter and a
timeout handling logic which really terminates the connection request upon
timeout. So the best way is to rely on this.
--
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]