system/settings: Fix non-cached save deadlock#3500
Open
nightt5879 wants to merge 2 commits into
Open
Conversation
Fix apache#3105 by making the immediate save path write pending settings while the caller still owns g_settings.mtx instead of calling the timer callback, which locks the same mutex again. The cached-save timer callback still takes the mutex before using the same locked helper, so asynchronous saves keep their existing synchronization while non-cached saves no longer depend on a recursive mutex. Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
The settings save path no longer re-enters g_settings.mtx, so the mutex does not need to be initialized as PTHREAD_MUTEX_RECURSIVE. This keeps the apache#3105 fix independent of CONFIG_PTHREAD_MUTEX_TYPES and destroys the temporary mutex attribute object after initialization. Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
xiaoxiang781216
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3105.
This PR fixes the settings deadlock that can happen when
CONFIG_SYSTEM_SETTINGS_CACHED_SAVESis disabled.Commit structure:
system/settings: Avoid recursive save locking) is the strict [BUG] Deadlock issue in system/settings when CONFIG_SYSTEM_SETTINGS_CACHED_SAVES is not set #3105 fix. The immediate save path now writes pending settings through a helper that assumesg_settings.mtxis already held, instead of calling the timer callback that locks the same mutex again. The cached-save timer callback still takes the mutex before using the same helper.system/settings: Drop unused recursive mutex type) is a small related cleanup. Since the settings save path no longer re-entersg_settings.mtx, the mutex no longer needsPTHREAD_MUTEX_RECURSIVE; this also keeps the fix independent ofCONFIG_PTHREAD_MUTEX_TYPES. It also destroys the temporary mutex attribute object after initialization.The second commit is logically separable and I am happy to drop it if maintainers consider it out of scope for #3105.
Out of scope:
Impact
With cached saves disabled, settings operations that save immediately no longer try to lock
g_settings.mtxrecursively viadump_cache().Testing
Host:
Checks:
git diff --check upstream/master..HEAD: passcheckpatch.sh -c -u -m -g HEAD~2..HEAD: passsim:nshbuild: passCONFIG_SYSTEM_SETTINGS=y# CONFIG_SYSTEM_SETTINGS_CACHED_SAVES is not set# CONFIG_PTHREAD_MUTEX_TYPES is not setCC: settings.cSIM elf with dynamic libs archive in nuttx.tgzNote: the temporary test build appended config overrides after configuring
sim:nsh, so.configprinted expected override warnings for the settings and pthread mutex options.