[
https://issues.apache.org/jira/browse/CAMEL-27042?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-27042 started by shashank.
----------------------------------------
> camel-paho-mqtt5 - a subscription the broker refuses (SUBACK reason code 0x80
> or higher) is taken as a success, so the route starts and never receives a
> message
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27042
> URL: https://issues.apache.org/jira/browse/CAMEL-27042
> Project: Camel
> Issue Type: Bug
> Components: camel-paho-mqtt5
> Reporter: shashank
> Assignee: shashank
> Priority: Major
>
> Found while checking the calls of the consumer against Paho 1.2.5 (javap) for
> the Paho DST world of CAMEL-26958 (PR #30138); the fake of that world does
> not model refused subscriptions, so the world does not drive it. Reproduced
> with a plain unit test (below).
> h3. What happens
> The consumer subscribes with {{MqttClient.subscribe(topic, qos)}} on start
> ({{doStart}}), after an automatic reconnect of the client ({{resubscribe}},
> CAMEL-24511) and after its own reconnect when the broker did not keep the
> session ({{reconnect}}). It does not look at the result.
> In MQTT 5 a broker that refuses a subscription still answers with a SUBACK,
> whose reason code is 0x80 or higher: 0x80 Unspecified error, 0x83
> Implementation specific error, 0x87 Not authorized, 0x8F Topic Filter
> invalid, 0x97 Quota exceeded, 0x9E Shared Subscriptions not supported, 0xA1,
> 0xA2 (MQTT 5.0, 3.9.3, and 2.4: a reason code of 0x80 or greater indicates
> failure). Paho 1.2.5 completes the token of the SUBSCRIBE with the reason
> codes of the SUBACK and no exception (read with javap:
> {{ClientState.notifyReceivedAck}} turns only a failed PUBREC into an
> exception; {{Token.markComplete}} copies the SUBACK reason codes to the
> token; {{MqttClient.subscribe}} waits for the token and returns it). The Paho
> MQTT 3 client 1.2.5 throws {{MqttException(128)}} for a granted QoS of 0x80
> in {{MqttClient.subscribe}}, so camel-paho gets this check from Paho.
> So with camel-paho-mqtt5 a route whose subscription is refused (an ACL that
> does not allow the topic, for example) starts, reports Started, and never
> receives a message; after a reconnect the resubscribe of CAMEL-24511 counts a
> refused subscription as done, so the route that CAMEL-24511 wanted restarted
> keeps running without its subscription.
> h3. Expected
> A refused subscription is a failed subscribe: the route does not start (as
> when the subscribe throws), and a refused resubscribe after a reconnect takes
> the path of a failed resubscribe (CAMEL-24511: the route is restarted for an
> own client, an error is logged for a client given with the {{client}}
> option). The same for the subscribe after the reconnect of a failed message
> (CAMEL-25793) when the broker did not keep the session: that connect created
> a kept session, so a later reconnect finds it and does not subscribe, and the
> consumer would stay connected without its subscription.
> h3. Reproduction
> New {{PahoMqtt5SubscribeRefusedTest}} (a mocked {{MqttClient}} whose
> subscribe returns a token with reason code 0x87, as Paho does): on main the
> route starts, a refused resubscribe after {{connectComplete(reconnect=true)}}
> leaves the route Started, and so does a refused subscribe after the reconnect
> of a failed message; a granted subscription (reason code 2) is the control.
> h3. Fix
> The consumer subscribes through one method that throws {{MqttException}} with
> the reason code (its message is the one of Paho's catalog, e.g. Not
> authorized.) when the SUBACK has a reason code of 0x80 or higher, used in the
> three places; a failed subscribe after the reconnect of a failed message
> restarts the route, as a failed resubscribe does. A granted QoS lower than
> the requested one is not a failure and is left as is. Branch
> {{camel-paho-mqtt5-suback-failure}}.
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)