Skip to content

Fix potential deadlock by resetting config before finalizing state#459

Merged
simo5 merged 1 commit into
latchset:mainfrom
simo5:deadlock_2
Jun 15, 2026
Merged

Fix potential deadlock by resetting config before finalizing state#459
simo5 merged 1 commit into
latchset:mainfrom
simo5:deadlock_2

Conversation

@simo5

@simo5 simo5 commented Jun 5, 2026

Copy link
Copy Markdown
Member

Description

This PR swaps the order of operations in the finalize function to ensure the global configuration is reset before the state is finalized. Although the write lock on STATE is supposed to be released before the CONFIG lock is acquired, we have observed deadlocks in some builds, likely because STATE does not immediately go out of scope.

By ensuring the CONFIG lock is always acquired prior to the STATE lock, we align with the locking order used throughout the rest of the codebase and eliminate this potential deadlock.

NOTE: this happens only when tests are run with high parallelization where they repeately initialize and tear down tokens for now, it is very unlikely to happen in a real application.

Checklist

  • Test suite updated
  • Rustdoc string were added or updated
  • CHANGELOG and/or other documentation added or updated
  • This is not a code change

Reviewer's checklist:

  • Any issues marked for closing are fully addressed
  • There is a test suite reasonably covering new functionality or modifications
  • This feature/change has adequate documentation added
  • A changelog entry is added if the change is significant
  • Code conform to coding style that today cannot yet be enforced via the check style test
  • Commits have short titles and sensible text
  • Doc string are properly updated

This commit swaps the order of operations in the finalize function
to ensure the global configuration is reset before the state is
finalized. Although the write lock on STATE is supposed to be released
before the CONFIG lock is acquired, we have observed deadlocks in some
builds, likely because STATE does not immediately go out of scope.

By ensuring the CONFIG lock is always acquired prior to the STATE lock,
we align with the locking order used throughout the rest of the codebase
and eliminate this potential deadlock.

Assisted-by: Gemini <gemini@google.com>
Signed-off-by: Simo Sorce <simo@redhat.com>
@simo5 simo5 requested a review from Jakuje June 5, 2026 16:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the finalize function in src/fns/general.rs to reorder the finalization steps, resetting the global configuration (CONFIG) before finalizing the global state (STATE). There are no review comments provided, and the changes appear straightforward, so I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@simo5 simo5 merged commit 0db21a8 into latchset:main Jun 15, 2026
50 checks passed
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.

2 participants