Skip to content

Conversation

@eduelias
Copy link

Motivation

This PR addresses MQTT connection reliability issues and adds support for the latest AWS IoT Device SDK C++ v2 (v1.40.2), along with improved build support for Fedora-based systems.

Background:

  • Production systems experiencing DUPLICATE_CLIENT_ID errors during unclean service restarts
  • AWS SDK v1.40.2 introduced breaking changes to socket API that prevented compilation of secure tunneling and sensor-publish features
  • Need for configurable MQTT session behavior to support different reliability requirements
  • Lack of official Fedora Docker build support

Issue number: N/A (proactive improvements)

Modifications

Change summary

1. Configurable Clean Session Flag

  • Added clean-session boolean configuration option (defaults to true)
  • Prevents DUPLICATE_CLIENT_ID errors by automatically disconnecting previous sessions
  • Allows users to choose between session persistence (QoS 1+ message queuing) vs connection reliability
  • Updated Config.h, Config.cpp, config-template.json, and documentation

2. AWS IoT Device SDK C++ v2 Update to v1.40.2

  • Updated from commit 74c8b683 to 0d29d85a (v1.40.2)
  • Fixed socket API compatibility in TcpForward.cpp and Socket.h to use new aws_socket_connect_options structure
  • All features now compile successfully with latest SDK

3. Improved MQTT Disconnect Handling

  • Enhanced SharedCrtResourceManager::disconnect() with forced cleanup on timeout
  • Disables auto-reconnection during shutdown
  • Adds 2-second grace period for broker propagation
  • Better logging for disconnect states

4. Enhanced Systemd Service Configuration

  • Increased TimeoutStopSec to 30 seconds for graceful MQTT disconnect
  • Added restart loop prevention (max 5 restarts in 5 minutes)
  • Proper signal handling with KillMode=mixed and SIGTERMSIGKILL cascade
  • Increased file descriptor limit to 65536

5. Fedora Build Support

  • Added Fedora 42 Dockerfile following Amazon Linux pattern
  • Builds OpenSSL 3.0.8 and CMake 3.24.4 from source for consistency
  • Integrated with existing docker-build.sh script
  • Multi-stage build for minimal runtime image

6. Additional Fixes

  • Replaced vfork() with fork() in JobEngine.cpp (more portable, safer)
  • Fixed dangling pointer in ConfigShadow.cpp
  • Added .dockerignore for cleaner Docker builds
  • Improved logging to show cleanSession value on connection

Revision diff summary

This is the initial submission.

Testing

Is your change tested? If not, please justify the reason.
✅ Yes, changes have been tested locally.

Please list your testing steps and test results.
WIP: Working on updating/fixing the tests now

1. macOS ARM64 Build Test

mkdir build && cd build
cmake ..
cmake --build . --target aws-iot-device-client

- Add configurable 'clean-session' MQTT option to prevent DUPLICATE_CLIENT_ID
- Update AWS IoT Device SDK to v1.40.2 (0d29d85a)
- Fix socket API compatibility for secure tunneling and sensor-publish
- Improve disconnect cleanup with forced connection reset
- Enhance systemd service configuration for graceful shutdown
- Add Fedora 42 Docker build support
- Replace vfork() with fork() in JobEngine
- Fix dangling pointer in ConfigShadow

These changes improve connection reliability and add support for the
latest SDK version with all features enabled.
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.

1 participant