Commit 0ea408e
fix: MQTT settings silently fail to persist when broker is unreachable (#9934)
* fix: MQTT settings silently fail to persist when broker is unreachable
isValidConfig() was testing broker connectivity via connectPubSub() as
part of config validation. When the broker was unreachable (network not
ready, DNS failure, server down), the function returned false, causing
AdminModule to skip saving settings entirely — silently.
This removes the connectivity test from isValidConfig(), which now only
validates configuration correctness (TLS support, default server port).
Connectivity is handled by the MQTT module's existing reconnect loop.
Fixes #9107
* Add client warning notification when MQTT broker is unreachable
Per maintainer feedback: instead of silently saving when the broker
can't be reached, send a WARNING notification to the client saying
"MQTT settings saved, but could not reach the MQTT server."
Settings still always persist regardless of connectivity — the core
fix from the previous commit is preserved. The notification is purely
advisory so users know to double-check their server address and
credentials if the connection test fails.
When the network is not available at all, the connectivity check is
skipped entirely with a log message.
* Address Copilot review feedback
- Fix warning message wording: "Settings will be saved" instead of
"Settings saved" (notification fires before AdminModule persists)
- Add null check on clientNotificationPool.allocZeroed() to prevent
crash if pool is exhausted (matches AdminModule::sendWarning pattern)
- Fix test comments to accurately describe conditional connectivity
check behavior and IS_RUNNING_TESTS compile-out
* Remove connectivity check from isValidConfig entirely
Reverts the advisory connectivity check added in the previous commit.
While the intent was to warn users about unreachable brokers,
connectPubSub() mutates the isConnected state of the running MQTT
module and performs synchronous network operations that can block
the config-save path.
The cleanest approach: isValidConfig() validates config correctness
only (TLS support, default server port). The MQTT reconnect loop
handles connectivity after settings are persisted and the device
reboots. If the broker is unreachable, the user will see it in the
MQTT connection status — no special notification needed.
This returns to the simpler design from the first commit, which was
tested on hardware and confirmed working.
* Use lightweight TCP check instead of connectPubSub for validation
Per maintainer feedback: users need connectivity feedback, but
connectPubSub() mutates the module's isConnected state.
This uses a standalone MQTTClient TCP connection test that:
- Checks if the server IP/port is reachable
- Sends a WARNING notification if unreachable
- Does NOT establish an MQTT session or mutate any module state
- Does NOT block saving — isValidConfig always returns true
The TCP test client is created locally, used, and destroyed within
the function scope. No side effects on the running MQTT module.
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>1 parent 644d0d4 commit 0ea408e
2 files changed
+34
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
654 | | - | |
655 | 654 | | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
| 655 | + | |
661 | 656 | | |
662 | 657 | | |
663 | 658 | | |
664 | | - | |
665 | | - | |
666 | 659 | | |
667 | | - | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
668 | 664 | | |
669 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
670 | 682 | | |
671 | 683 | | |
672 | 684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
821 | | - | |
| 821 | + | |
| 822 | + | |
822 | 823 | | |
823 | 824 | | |
824 | 825 | | |
825 | | - | |
826 | 826 | | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
| 827 | + | |
831 | 828 | | |
832 | 829 | | |
833 | 830 | | |
| |||
846 | 843 | | |
847 | 844 | | |
848 | 845 | | |
849 | | - | |
| 846 | + | |
850 | 847 | | |
851 | 848 | | |
852 | 849 | | |
853 | | - | |
854 | 850 | | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
| 851 | + | |
859 | 852 | | |
860 | 853 | | |
861 | | - | |
862 | | - | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
863 | 857 | | |
864 | 858 | | |
865 | | - | |
866 | | - | |
867 | 859 | | |
868 | | - | |
| 860 | + | |
869 | 861 | | |
870 | 862 | | |
871 | 863 | | |
872 | 864 | | |
873 | 865 | | |
874 | 866 | | |
875 | | - | |
876 | 867 | | |
877 | 868 | | |
878 | | - | |
| 869 | + | |
879 | 870 | | |
880 | | - | |
| 871 | + | |
881 | 872 | | |
882 | 873 | | |
883 | 874 | | |
| |||
927 | 918 | | |
928 | 919 | | |
929 | 920 | | |
930 | | - | |
| 921 | + | |
931 | 922 | | |
932 | 923 | | |
933 | 924 | | |
| |||
0 commit comments