Skip to content

fix: Increase default MQTT payload size to 256 MiB#3130

Merged
albinsuresh merged 2 commits intothin-edge:mainfrom
albinsuresh:fix/3124/increase-default-mqtt-message-size
Sep 27, 2024
Merged

fix: Increase default MQTT payload size to 256 MiB#3130
albinsuresh merged 2 commits intothin-edge:mainfrom
albinsuresh:fix/3124/increase-default-mqtt-message-size

Conversation

@albinsuresh
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh commented Sep 23, 2024

Proposed changes

  • Increase default MQTT payload size to 256 MiB
  • Make MQTT cloud payload size configurable

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#3124

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 23, 2024

mqtt_schema,
tedge_config.aws.mapper.timestamp_format,
prefix.clone(),
tedge_config.az.mapper.mqtt.max_payload_size,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy/paste typo

Suggested change
tedge_config.az.mapper.mqtt.max_payload_size,
tedge_config.aws.mapper.mqtt.max_payload_size,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 23, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
506 0 2 506 100 1h28m58.305465999s

@albinsuresh albinsuresh force-pushed the fix/3124/increase-default-mqtt-message-size branch from 6b0ae87 to 59a1618 Compare September 24, 2024 06:18
Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

The issue is addressed by the proposed fix. However, this introduces a weakness, and I would consider to limit the size of the messages actually processed by thin-edge, ignoring those too large.

Comment on lines +167 to +169
max_packet_size: 1024 * 1024,
max_packet_size: MAX_PACKET_SIZE,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking closer to root cause of an infinite loop caused by a message that is too large, it appears that the issue is not rooted in the MQTT protocol per se, but is due to a bad combination of rumqttc and thin-edge.

  • when a message that is too large is received, rumqttc raises a PayloadSizeLimitExceeded error
  • when this error is received thin-edge do nothing beyond logging and adding some delay (which is useless)
  • rumqttc also cuts the connection and then reconnects.
  • the message is then resent by the broker that is still expecting an acknowledgement.

Unfortunately, the rumqttc API provides no means to skip that poison pill (the error structs does not contain the message pkid).

=> Removing the limit as done here fixes the issue. However, we can consider to add our own check with no limit on what is received from rumqttc but with a filter implemented by mqtt_channel to prune messages that are too large. Without this limit a rogue client might overwhelmed the mapper or the agent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved a4a6af9

Copy link
Copy Markdown
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

One suggestion

mqtt: {
/// The maximum message payload size that can be mapped to the cloud
#[tedge_config(example = "8192", default(variable = "C8Y_MQTT_PAYLOAD_LIMIT"))]
max_payload_size: u32,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The maximum size of u32 is much bigger than 256MiB. (4294967295 > 268435455). I think we need protection for such big input from user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved by f32c709

mqtt_schema,
tedge_config.aws.mapper.timestamp_format,
prefix.clone(),
tedge_config.aws.mapper.mqtt.max_payload_size,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Related to my comment above, for example, here we can add the size check for aws.mapper.mqtt.max_payload_size

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented the validation at the tedge_config level itself, so that the user gets the feedback much earlier.

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

The code is correct. I would prefer to revert the default max size to the previous values.

/// Maximum size for a message payload
///
/// Default: `1024 * 1024`.
/// Default: `268435455` (256 MB).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would not change the default, now that the correct protection is implemented.

Suggested change
/// Default: `268435455` (256 MB).
/// Default: `1024 * 1024`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved by f43495e

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

}
}

impl TryFrom<u32> for MqttPayloadLimit {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't have gone so far. But since this has been done, we can keep it.

@albinsuresh albinsuresh force-pushed the fix/3124/increase-default-mqtt-message-size branch from f43495e to 7dbd1aa Compare September 27, 2024 04:24
@albinsuresh albinsuresh added this pull request to the merge queue Sep 27, 2024
Merged via the queue into thin-edge:main with commit af73e0c Sep 27, 2024
@reubenmiller reubenmiller changed the title Increase default MQTT payload size to 256 MiB fix: Increase default MQTT payload size to 256 MiB Oct 2, 2024
@reubenmiller reubenmiller added the theme:mqtt Theme: mqtt and mosquitto related topics label Oct 2, 2024
@albinsuresh albinsuresh deleted the fix/3124/increase-default-mqtt-message-size branch October 22, 2024 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:mqtt Theme: mqtt and mosquitto related topics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants