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: prevent store message on store when it's restored #1255

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

ogis-yamazaki
Copy link
Contributor

Cause

The message restored from the store was written to the store again before sending.
The writing is a time-consuming process of updating the stored message.
Meanwhile, next message overtook.

Fixes

The restored message was sent without being written to the store.

Added noStore flag to _sendStore function.

@ogis-yamazaki ogis-yamazaki changed the title fix #1239 fix message overtaking Mar 4, 2021
@ogis-yamazaki ogis-yamazaki force-pushed the fix_message_overtaking branch 2 times, most recently from 3f5084c to 5449aaf Compare June 22, 2021 01:20
@ogis-yamazaki
Copy link
Contributor Author

@YoDaMa

Rebased with the latest master.
Please confirm.

@YoDaMa
Copy link
Contributor

YoDaMa commented Jun 24, 2021

hey @ogis-fujiwara, looks good. could you provide a repro of this behavior?

I want to add a test to actually catch this behavior we can demonstrate that this is fixing the bug, and that any future changes don't rollback this fix.

@ogis-yamazaki
Copy link
Contributor Author

@YoDaMa

Added a replay test. We have also confirmed that the bug is fixed.

Copy link
Contributor

@YoDaMa YoDaMa left a comment

Choose a reason for hiding this comment

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

I'm still not positive that this is the right move. You're removing the storage of the message which could create a new case with a bug.

What would happen if we follow your repro but after it reconnects it sends the initial packet again which is lost? It's not stored in the store before sending so it will not be resent...

@ogis-yamazaki
Copy link
Contributor Author

ogis-yamazaki commented Dec 24, 2021

@YoDaMa

I'm still not positive that this is the right move. You're removing the storage of the message which could create a new case with a bug.

PR did not seem to solve the essential problem.
I have recreated the PR, so please check it. 6d77f3e

The underlying problem was that external stores, such as mqtt-level-db, sometimes did not return callbacks in the order they were requested.

The callbacks for the external store are called in no particular order, as shown in the following link.

Level/leveldown#797

Added an internal queue so that it does not depend on the callback timing of the external store.

@redboltz
Copy link
Contributor

redboltz commented Jan 6, 2022

@YoDaMa , @ogis-yamazaki and I are working on the same project that uses MQTT.js.
I reviewed the original version of the PR and I noticed that it is NOT an essential fix.
So I proposed the essential fix, then @ogis-yamazaki apply it and force pushed to the PR.
That is way 6d77f3e is my commit.

I believe that this PR is ready to merge.

@ogis-yamazaki
Copy link
Contributor Author

Rebased on the latest main branch.

Overtaking still occurs in v4.3.7, so this PR is needed.

@ogis-yamazaki ogis-yamazaki changed the base branch from master to main November 11, 2022 02:57
@ogis-yamazaki ogis-yamazaki force-pushed the fix_message_overtaking branch 3 times, most recently from c0d4990 to f2c33b0 Compare November 11, 2022 05:47
@codecov
Copy link

codecov bot commented Nov 11, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03 🎉

Comparison is base (a170c54) 86.22% compared to head (c05c4dd) 86.25%.

❗ Current head c05c4dd differs from pull request most recent head f0ce93f. Consider uploading reports for the commit f0ce93f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1255      +/-   ##
==========================================
+ Coverage   86.22%   86.25%   +0.03%     
==========================================
  Files          13       13              
  Lines        1314     1317       +3     
==========================================
+ Hits         1133     1136       +3     
  Misses        181      181              
Impacted Files Coverage Δ
lib/client.js 90.90% <100.00%> (+0.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@robertsLando
Copy link
Member

Is this still good to merge?

@ogis-yamazaki ogis-yamazaki force-pushed the fix_message_overtaking branch 4 times, most recently from 4d310a5 to e6c80b2 Compare June 26, 2023 04:31
@ogis-yamazaki
Copy link
Contributor Author

@robertsLando

Rebased PR using the latest main branch.
Verified that the test passes.
Merge this in.

@robertsLando robertsLando changed the title fix message overtaking fix: prevent store message on store when it's restored Jun 26, 2023
lib/client.js Show resolved Hide resolved
@robertsLando robertsLando requested review from YoDaMa and removed request for YoDaMa June 26, 2023 07:32
@ogis-yamazaki ogis-yamazaki force-pushed the fix_message_overtaking branch 2 times, most recently from b623c46 to 9ea980c Compare June 28, 2023 00:31
Added reproduction test case for mqttjs#1254
@ogis-yamazaki
Copy link
Contributor Author

@robertsLando

I've added a comment.

@robertsLando robertsLando merged commit 8d68c8c into mqttjs:main Jun 28, 2023
4 checks passed
@ogis-yamazaki ogis-yamazaki deleted the fix_message_overtaking branch June 28, 2023 07:50
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.

None yet

4 participants