Skip to content
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

Fix for unlimited maximum message expiry interval #315

Merged
merged 14 commits into from
Oct 21, 2023
Merged

Fix for unlimited maximum message expiry interval #315

merged 14 commits into from
Oct 21, 2023

Conversation

dadebue
Copy link
Contributor

@dadebue dadebue commented Oct 4, 2023

fixes #306

@dadebue dadebue changed the title fix when no max msg expiry interval is set Fix for unlimited maximum message expiry interval Oct 4, 2023
server.go Show resolved Hide resolved
@dadebue dadebue requested a review from werbenhu October 10, 2023 10:02
@werbenhu werbenhu requested review from dgduncan and mochi-co October 10, 2023 11:43
@mochi-co
Copy link
Collaborator

I will try to look at this today, apologies for the delay

mochi-co and others added 2 commits October 12, 2023 14:41
…et to 0 or math.MaxInt64 for no expiry, and optimize some of the code and test cases.
@coveralls
Copy link

coveralls commented Oct 13, 2023

Pull Request Test Coverage Report for Build 6541851124

  • 26 of 26 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 98.912%

Totals Coverage Status
Change from base Build 6536886378: 0.004%
Covered Lines: 5455
Relevant Lines: 5515

💛 - Coveralls

werbenhu
werbenhu previously approved these changes Oct 13, 2023
@werbenhu werbenhu requested review from dgduncan and mochi-co and removed request for dgduncan and mochi-co October 13, 2023 08:10
werbenhu
werbenhu previously approved these changes Oct 13, 2023
@werbenhu werbenhu self-requested a review October 13, 2023 08:49
werbenhu
werbenhu previously approved these changes Oct 13, 2023
@werbenhu werbenhu requested review from werbenhu and removed request for werbenhu October 13, 2023 11:19
@werbenhu werbenhu dismissed stale reviews from dgduncan and themself via 97441eb October 14, 2023 23:45
werbenhu
werbenhu previously approved these changes Oct 14, 2023
@werbenhu werbenhu requested a review from mochi-co October 14, 2023 23:53
@mochi-co
Copy link
Collaborator

@werbenhu The current changes on the branch don't fully comply with the scenarios in #315 (comment) - With s.Options.Capabilities.MaximumMessageExpiryInterval == math.MaxInt64 we should still continue to expire messages which have their own set expiry values set.

I'd recommend reviewing the diff I posted above as I believe this addresses all the scenarios we are trying to fix.

…iration checks if MaximumMessageExpiryInterval is set to 0; optimize code and test cases.
@werbenhu
Copy link
Member

I'm just catching up on this and it sounds like there are some misunderstandings on the spec and current design, but to confirm:

  • Setting s.Options.Capabilities.MaximumMessageExpiryInterval == math.MaxInt64 should not disable message expiry, it should be honoured even though it is infinitely in the future - unless there is a significant performance reason not to do so (I am unaware of such a thing currently).
  • if s.Options.Capabilities.MaximumMessageExpiryInterval is 1 or more, message expiry per message must still be honoured per the MQTTv5 spec if set in the message properties, but MQTTv3 messages and those without expiries should be retained forever.
  • if s.Options.Capabilities.MaximumMessageExpiryInterval is 0, message expiry per message must be ignored for all messages and protocols.

(edited - apologies it's late and I've been extraordinarily busy)

It's done now.

@werbenhu
Copy link
Member

There still seem to be some issues here, I'll need to make some submissions later

clients.go Outdated Show resolved Hide resolved
server.go Outdated Show resolved Hide resolved
@mochi-co
Copy link
Collaborator

There still seem to be some issues here, I'll need to make some submissions later

Which issues are you seeing?

…he message's own expiration(for v5) evaluation.
@werbenhu
Copy link
Member

I still think that we shouldn't disable the clearing of expired retained messages if s.Options.Capabilities.MaximumMessageExpiryInterval == math.MaxInt64 ``

What would be the result if a sender sends a retained message that has a expiry of 1 hour but s.Options.Capabilities.MaximumMessageExpiryInterval == math.MaxInt64? The message will not be deleted from the broker because clearing of retained messages is disabled and therefore will not expire in 1 hour as the sender intended...

What do you think?

@mochi-co I think @dadebue is right, and I've made some changes to it.

@werbenhu
Copy link
Member

werbenhu commented Oct 16, 2023

@mochi-co take a look at the current implementation. I always feel that what's written here in func (cl *Client) ClearInflights(now, maximumExpiry int64) []uint16 isn't concise and clear enough;

'maximumExpiry=0' carries a dual meaning:

  • When calling cl.ClearInflights() within server.clearExpiredInflights, 'maximumExpiry=0' means there's no need to process the maximum.
  • When calling cl.ClearInflights() within server.inheritClientSession, 'maximumExpiry=0' indicates the need to forcibly clear all client inflights. Therefore, here I use maximumExpiry=-1 to denote a forced clear.

@dadebue
Copy link
Contributor Author

dadebue commented Oct 16, 2023

I like the current implementation.

Maybe we should change the name abandoned to something different. What the maximum expiry interval is doing is forcing the expiry of old messages. Why don't we call it forceExpiry then?

@werbenhu werbenhu requested a review from mochi-co October 17, 2023 02:41
@werbenhu
Copy link
Member

@dadebue @mochi-co I have added client.ClearExpiredInflights() to clear expired messages, while client.ClearInflights() is used to clear all inflight messages. Please review the code again. Thanks.

@dadebue
Copy link
Contributor Author

dadebue commented Oct 17, 2023

I approve the changes with this comment ☺️ (I can't approve in GitHub as I wasn't requested to review)

@werbenhu werbenhu requested review from IshanDaga and removed request for IshanDaga October 17, 2023 10:34
@werbenhu
Copy link
Member

@dadebue Because you are the author of this PR.:smile:

@dadebue dadebue mentioned this pull request Oct 18, 2023
Copy link
Collaborator

@mochi-co mochi-co left a comment

Choose a reason for hiding this comment

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

It took a bit of a confusing road to get here, but I've given it a thorough review and it makes sense to me, and I think this is an excellent solution which makes the overall codebase a bit cleaner and easier to understand. Paho and unit tests are also passing, so I approve! Great job @werbenhu @dadebue

@mochi-co mochi-co merged commit 4c0c862 into mochi-mqtt:main Oct 21, 2023
@dadebue
Copy link
Contributor Author

dadebue commented Nov 24, 2023

@mochi-co @dgduncan @werbenhu what's is the release schedule for this repo? When will all the changes since October 2nd be released?

@mochi-co
Copy link
Collaborator

@dadebue Apologies, I've had some big life stuff going on and the time got away from me. I've released these changes as v2.4.2 :)

@dadebue
Copy link
Contributor Author

dadebue commented Nov 24, 2023

No worries and thanks :)

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

Successfully merging this pull request may close these issues.

Default value of MaximumMessageExpiryInterval
5 participants