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

rumqttc: resume session only if CONNACK with session present 1 #864

Merged
merged 13 commits into from
May 21, 2024

Conversation

xiaocq2001
Copy link
Contributor

@xiaocq2001 xiaocq2001 commented May 14, 2024

Type of change

Implement for #863.

Bug fix (non-breaking change which fixes an issue):

In MQTT, session is not always resumed, but in current mqttc the pending publishes are restored anyway.
With this fix the CONNACK session present returned from broker is checked, to confirm if a session is actually resumed, if not the pending publishes are cleaned and new session is started.

Checklist:

  • Formatted with cargo fmt
  • Make an entry to CHANGELOG.md if it's relevant to the users of the library. If it's not relevant mention why.

rumqttc/src/v5/eventloop.rs Outdated Show resolved Hide resolved
Copy link
Member

@de-sh de-sh left a comment

Choose a reason for hiding this comment

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

@xiaocq2001 xiaocq2001 changed the title rumqttc: in v5, resume session only if CONNACK with session present 1 rumqttc: resume session only if CONNACK with session present 1 May 15, 2024
@de-sh de-sh requested a review from swanandx May 16, 2024 13:15
@swanandx
Copy link
Member

can you please fix the code / tests?

the reconnection_resends_unacked_packets_from_the_previous_connection_first test is failing, i think we need to connect with clean session false so that broker will save the state right?

@xiaocq2001
Copy link
Contributor Author

To test, I think we need #854. With that, we need to connect with clean session false and session expiry interval non-zero to let broker save state.

@xiaocq2001
Copy link
Contributor Author

xiaocq2001 commented May 20, 2024

To test, I think we need #854. With that, we need to connect with clean session false and session expiry interval non-zero to let broker save state.

Facing an issue on connection.

---- reconnection_resumes_from_the_previous_state stdout ----
Polled = Ok(Incoming(ConnAck(ConnAck { session_present: false, code: Success })))
Polled = Ok(Outgoing(Publish(1)))
Polled = Ok(Incoming(PubAck(PubAck { pkid: 1 })))
Polled = Ok(Outgoing(Publish(2)))
Polled = Ok(Incoming(PubAck(PubAck { pkid: 2 })))
Polled = Ok(Outgoing(Publish(3)))
Polled = Ok(Outgoing(Publish(4)))
Polled = Ok(Outgoing(Publish(5)))
Polled = Ok(Outgoing(PingReq))
Polled = Ok(Outgoing(Publish(6)))
Polled = Ok(Outgoing(Publish(7)))
Polled = Ok(Outgoing(Publish(8)))
Polled = Ok(Outgoing(Publish(9)))
Polled = Ok(Outgoing(Publish(10)))
Polled = Err(MqttState(AwaitPingResp))
Polled = Ok(Incoming(ConnAck(ConnAck { session_present: false, code: Success })))

It seems on host side session is not stored?

Another question: due to MQTT protocol difference between versions, in v5 session_expiry_interval is supported but in v3 it is not, what is the suggestion on handling such difference in tests?

@de-sh
Copy link
Member

de-sh commented May 20, 2024

To test, I think we need #854. With that, we need to connect with clean session false and session expiry interval non-zero to let broker save state.

Facing an issue on connection.

---- reconnection_resumes_from_the_previous_state stdout ----
Polled = Ok(Incoming(ConnAck(ConnAck { session_present: false, code: Success })))
Polled = Ok(Outgoing(Publish(1)))
Polled = Ok(Incoming(PubAck(PubAck { pkid: 1 })))
Polled = Ok(Outgoing(Publish(2)))
Polled = Ok(Incoming(PubAck(PubAck { pkid: 2 })))
Polled = Ok(Outgoing(Publish(3)))
Polled = Ok(Outgoing(Publish(4)))
Polled = Ok(Outgoing(Publish(5)))
Polled = Ok(Outgoing(PingReq))
Polled = Ok(Outgoing(Publish(6)))
Polled = Ok(Outgoing(Publish(7)))
Polled = Ok(Outgoing(Publish(8)))
Polled = Ok(Outgoing(Publish(9)))
Polled = Ok(Outgoing(Publish(10)))
Polled = Err(MqttState(AwaitPingResp))
Polled = Ok(Incoming(ConnAck(ConnAck { session_present: false, code: Success })))

It seems on host side session is not stored?

xiaocq2001#2 solves this inconsistency in the tests

Another question: due to MQTT protocol difference between versions, in v5 session_expiry_interval is supported but in v3 it is not, what is the suggestion on handling such difference in tests?

The tests focus mainly on v4 as of right now, we are yet to see contributions towards better testing the v5 code. But we are happy to...

@xiaocq2001
Copy link
Contributor Author

xiaocq2001 commented May 21, 2024

I realize that in failing tests, the broker is started by Broker::new, which starts a broker without any stored state, that's why broker send ConnAck with session present false, we need some new method to introduce disconnection, maybe like what is in async_manual_ack example.

OK. I saw the updates to update broker, that's great.

test: fix test to follow MQTT standards
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9166733626

Details

  • 11 of 23 (47.83%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.002%) to 36.201%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rumqttc/src/v5/eventloop.rs 0 12 0.0%
Files with Coverage Reduction New Missed Lines %
rumqttc/src/v5/eventloop.rs 3 8.99%
Totals Coverage Status
Change from base Build 9128770188: 0.002%
Covered Lines: 5987
Relevant Lines: 16538

💛 - Coveralls

@de-sh de-sh merged commit 83d8f77 into bytebeamio:main May 21, 2024
4 checks passed
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.

None yet

4 participants