Skip to content

Delete mqtt qos0 queue when mqtt 5.0 connection is closed #14006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

MarcialRosales
Copy link
Contributor

@MarcialRosales MarcialRosales commented Jun 2, 2025

Proposed Changes

Fix issue where an mqtt qos0 queue is left alive after its connection is closed. An mqtt 5.0 connection with Session Expiry Interval of 0 and clean start of 0 should be deleted when its connection is closed.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)
  • Build system and/or CI

@MarcialRosales MarcialRosales self-assigned this Jun 2, 2025
@MarcialRosales MarcialRosales changed the title Delete mqtt qos0 when connection is closed Delete mqtt qos0 quen when mqtt 5.0 connection is closed Jun 2, 2025
@MarcialRosales MarcialRosales changed the title Delete mqtt qos0 quen when mqtt 5.0 connection is closed Delete mqtt qos0 queue when mqtt 5.0 connection is closed Jun 2, 2025
@MarcialRosales MarcialRosales force-pushed the delete-qos0-queue branch 2 times, most recently from 3b2caee to 04a3aa5 Compare June 3, 2025 15:19
@MarcialRosales MarcialRosales marked this pull request as ready for review June 4, 2025 08:38
@MarcialRosales MarcialRosales force-pushed the delete-qos0-queue branch 2 times, most recently from 2b87f22 to 496b2d0 Compare June 4, 2025 08:41
@ansd ansd self-requested a review June 4, 2025 09:26
Comment on lines 1589 to 1590
zero_session_expiry_interval_disconnect_client(Config) ->
C = connect(?FUNCTION_NAME, Config, [{properties, #{'Session-Expiry-Interval' => 0}}]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case doesn't test the fix you provided.
In fact this test case succeeds even without your fix.

Specifically the bug is that an MQTT QoS 0 queue is not deleted by the MQTT plugin if an MQTT 5.0 client connects with CleanStart=false and a SessionExpiryInterval of 0.

Therefore, this test case should use {clean_start, false}.

I recommend moving this test case into the v5_SUITE since the combination of these two settings is an MQTT 5.0 specific feature.

Copy link
Contributor Author

@MarcialRosales MarcialRosales Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ansd I was following the 3 conditions in the docs https://www.rabbitmq.com/docs/mqtt#qos0-queue-type and it does not mention clean_start setting .. should it also be mentioned in the docs?

I started doing this test in v5_SUITE but then I found mqtt_shared_SUITE and I thought this suite would be the best place because both versions are tested ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it also be mentioned in the docs?

No, the docs are correct.

If anything, we can delete the 1st condition since it's no longer relevant. This feature flag has become required: rabbitmq/rabbitmq-website#2284

Copy link
Contributor Author

@MarcialRosales MarcialRosales Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reading (http://www.steves-internet-guide.com/mqttv5-clean-start-clean-sessions-and-session-expiry/) that clean_start is used in conjunction with session expiry interval . why do you think the documentation should not mention clean_start in the conditions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think the documentation should not mention clean_start in the conditions?

If no queue exists for an MQTT 5.0 client, and the client connects with a Session Expiry Interval of 0 subsequently subscribing with QoS 0, the MQTT plugin will create an MQTT QoS 0 queue for that client irrespective of whether the client connected with Clean Start 0 or 1.


ok = emqtt:disconnect(C),
%% After terminating a clean session, we expect any session state to be cleaned up on the server.
timer:sleep(200), %% Give some time to clean up exclusive classic queue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You copied this comment wrongly. It's not a classic queue that gets created, it's an MQTT QoS 0 queue.

@ansd
Copy link
Member

ansd commented Jun 4, 2025

To be extra clear: The bug was that an MQTT QoS 0 queue was not deleted by the MQTT plugin for an MQTT 5.0 client that connected with Clean Start 0 and Session Expiry Interval 0.

because it is a feature exclusive of v5
@michaelklishin michaelklishin added this to the 4.2.0 milestone Jun 4, 2025
@michaelklishin michaelklishin merged commit d8b3288 into main Jun 4, 2025
3 checks passed
@michaelklishin michaelklishin deleted the delete-qos0-queue branch June 4, 2025 14:49
@michaelklishin
Copy link
Collaborator

I have addressed the comment and trailing whitespace feedback.

mergify bot pushed a commit that referenced this pull request Jun 4, 2025
michaelklishin added a commit that referenced this pull request Jun 4, 2025
michaelklishin added a commit that referenced this pull request Jun 4, 2025
(cherry picked from commit 24464a6)
ansd added a commit that referenced this pull request Jun 4, 2025
Follow up of #14006
@ansd ansd mentioned this pull request Jun 4, 2025
michaelklishin added a commit that referenced this pull request Jun 4, 2025
Delete mqtt qos0 queue when mqtt 5.0 connection is closed

(cherry picked from commit d8b3288)
michaelklishin added a commit that referenced this pull request Jun 4, 2025
(cherry picked from commit 24464a6)
@ansd
Copy link
Member

ansd commented Jun 4, 2025

Thank you for this fix @MarcialRosales !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants