Release resource registry read lock before running handlers#281
Open
damilolaedwards wants to merge 1 commit into
Open
Release resource registry read lock before running handlers#281damilolaedwards wants to merge 1 commit into
damilolaedwards wants to merge 1 commit into
Conversation
Read held the registry read lock while invoking a resource handler. Handlers that list other resources, such as the getting-started guide, re-acquire the read lock, which deadlocks against a concurrent register from a datasource refresh once that register is queued on the write lock. Resolve the handler under the lock and run it after releasing, so a handler can safely call back into the registry. Add regression tests covering a concurrent register during a resource-listing handler and parallel reads racing a stream of registers.
samcm
approved these changes
Jul 6, 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.
Problem
registry.Readheld the registry read lock while invoking a resource handler. Some handlers list other resources while running: thepanda://getting-startedguide calls back intoListStatic/ListTemplates, which re-acquire the same read lock.Go's
sync.RWMutexrefuses a recursive read lock once a writer is waiting. Datasource discovery registers resources for modules that activate after startup (local refresh every 5s), callingRegisterStatic/RegisterTemplateunder the write lock. If such a register queues while a read is between its outer lock and the handler's inner lock, the reader blocks on the re-entrant read lock and the writer blocks on the reader, deadlocking. Because the read lock is then held forever, all later reads and the discovery refresh loop wedge until the process restarts.Fix
Resolve the handler and mime type under the read lock, release the lock, then run the handler. A handler can now safely call back into the registry. Match order (static before template) and error messages are unchanged.
Tests
Full
pkg/resourceandpkg/serversuites pass, including-race.