Repository navigation
Fix double mutex unlock when shrinking IO threads - #5366
rainsupreme merged 1 commit into
Conversation
updateIOThreads locks the mutex of every active IO thread and sets active_io_threads_num to 1 before resizing the pool. When shrinking, it then unlocked the mutex of each removed thread and called shutdownIOThread, which unlocks the same mutex again because the thread id is now above active_io_threads_num. Unlocking a mutex that is not locked is undefined behavior. Drop the unlock in updateIOThreads and let shutdownIOThread do it, the same way killIOThreads relies on it. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Review stateReady for human review. Risk: Low. A one-line removal on the CONFIG SET io-threads shrink path. If it were wrong, a removed IO thread would stay blocked and pthread_join would hang, and the existing io-threads.tcl shrink tests would catch that. Open findings: none. Backport: Needed for 9.2, 9.1, 9.0. upstream/9.2, 9.1 and 9.0 all have the extra pthread_mutex_unlock before shutdownIOThread in updateIOThreads, and shutdownIOThread there also unlocks inactive threads. 8.1, 8.0 and 7.2 do not have the shutdownIOThread unlock. Updated for 395c875 at 2026-11-11 22:38 UTC. The bot rewrites this comment on every review. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #5366 +/- ##
============================================
- Coverage 81.44% 81.42% -0.03%
============================================
Files 199 199
Lines 104752 104749 -3
============================================
- Hits 85316 85290 -26
- Misses 19436 19459 +23
π New features to boost your workflow:
|
rainsupreme
left a comment
There was a problem hiding this comment.
LGTM!
I built the base and your branch with error-checking mutexes in createIOThread, and made the unlock calls in shutdownIOThread and, on the base, updateIOThreads abort on a non-zero return. On the base, unit/io-threads aborts when it shrinks the pool from 5 to 1 threads: the unlock of thread 4 in shutdownIOThread fails with EPERM, because updateIOThreads has already unlocked it. With your change the same test passes. updateIOThreads sets active_io_threads_num to 1 before the loop, so shutdownIOThread unlocks every removed thread itself.
When the IO threads pool shrinks, updateIOThreads unlocks each removed thread's mutex and then calls shutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that is not locked is undefined behavior. The unlock in shutdownIOThread was added in #2898, but the older one in updateIOThreads was never removed. This PR removes it, so shutdownIOThread is the single owner of the unlock, as it already is for killIOThreads. No behavior change on Linux or macOS, where the second unlock on a default mutex returns 0; the existing io-threads.tcl shrink tests cover the path. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5366
When the IO threads pool shrinks, updateIOThreads unlocks each removed thread's mutex and then calls shutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that is not locked is undefined behavior. The unlock in shutdownIOThread was added in #2898, but the older one in updateIOThreads was never removed. This PR removes it, so shutdownIOThread is the single owner of the unlock, as it already is for killIOThreads. No behavior change on Linux or macOS, where the second unlock on a default mutex returns 0; the existing io-threads.tcl shrink tests cover the path. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5366
When the IO threads pool shrinks, updateIOThreads unlocks each removed thread's mutex and then calls shutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that is not locked is undefined behavior. The unlock in shutdownIOThread was added in #2898, but the older one in updateIOThreads was never removed. This PR removes it, so shutdownIOThread is the single owner of the unlock, as it already is for killIOThreads. No behavior change on Linux or macOS, where the second unlock on a default mutex returns 0; the existing io-threads.tcl shrink tests cover the path. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5366
When the IO threads pool shrinks, updateIOThreads unlocks each removed thread's mutex and then calls shutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that is not locked is undefined behavior. The unlock in shutdownIOThread was added in #2898, but the older one in updateIOThreads was never removed. This PR removes it, so shutdownIOThread is the single owner of the unlock, as it already is for killIOThreads. No behavior change on Linux or macOS, where the second unlock on a default mutex returns 0; the existing io-threads.tcl shrink tests cover the path. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5366
When the IO threads pool shrinks, updateIOThreads unlocks each removed thread's mutex and then calls shutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that is not locked is undefined behavior. The unlock in shutdownIOThread was added in #2898, but the older one in updateIOThreads was never removed. This PR removes it, so shutdownIOThread is the single owner of the unlock, as it already is for killIOThreads. No behavior change on Linux or macOS, where the second unlock on a default mutex returns 0; the existing io-threads.tcl shrink tests cover the path. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 5366
> [!CAUTION] > **Opened ready with 1 unresolved security item** (`force_ready` was set): release impact may require higher urgency or security treatment. Security classification is human-owned: settle the urgency and the Security Fixes entries (re-run the cut with them, or edit through review comments) before merging. All 4 flagged items: notes flagged low-confidence; AI triaged PRs without release-notes (confirm include/exclude); release impact may require higher urgency or security treatment; notes credited to a backport. Cuts **9.2.1** onto release line `9.2`. - Promotes the release notes into a dated section, bumps `src/version.h`, and refreshes the running contributor list. - Release notes computed over the range below (`9.2.0..9dc1926`): ``` mode: ga source_ref: 9.2 target_branch: 9.2 base: 9.2.0 @ d23684e head: 9dc1926 @ 9dc1926 ``` ###β οΈ Notes to double-check The generator flagged these notes low-confidence; confirm category and wording before merging: | PR | Category | Why flagged | |----|----------|-------------| | #5366 | Bug Fixes | explicit impact scope omitted: Linux | ###β οΈ Release impact and urgency need review Code detected release-impact terms (availability, memory safety, data integrity, access control, protocol, compatibility) in these PRs; this forces review, it is not a severity classification. The requested urgency is **MODERATE**. Confirm whether these changes require `HIGH`, `CRITICAL`, or `SECURITY`, and whether any need a hand-authored **Security Fixes** entry: <details> <summary>7 PR(s) with impact signals</summary> | PR | Title | Signal | |----|-------|--------| | [#5366](#5366) | Fix double mutex unlock when shrinking IO threads | undefined behavior or unsafe arithmetic | | [#5468](#5468) | Don't resend data to a close_asap client after an IO-thread write | server crash, assertion, or availability failure | | [#5112](#5112) | Pause rehashing of path hash payloads during background iteration | server crash, assertion, or availability failure | | [#4712](#4712) | Fix execGetKeys() dropping the first 256 keys past the static buffer | server crash, assertion, or availability failure | | [#4675](#4675) | Fix cluster bus self-forget use-after-free | memory-safety risk | | [#5452](#5452) | Ignore replica claims that would close a replicaof cycle | server crash, assertion, or availability failure | | [#3245](#3245) | Fix assertion crash in processIOThreadsReadDone when DONT_PARSE client has stale argc | server crash, assertion, or availability failure | </details> ### Triage summary - 8 PR(s) triaged into the notes - 3 PR(s) triaged out Per-PR verdicts (with reasons) are in the run's `triage-verdicts` artifact. To include a wrongly-dropped PR, label it `release-notes` and re-cut. ###β οΈ Notes credited to a backport (original PR not recovered) These notes credit the backport PR, not the change's author; confirm the original PR and correct the credit before merging: | Backport PR | Title | |-------------|-------| | [#5550](#5550) | [9.2] Revert fail-fast TLS certificate checks (#2999, #3522) | ### Wording carried from other release lines A backported change is cut once per release line, and each cut words its notes independently. To keep one commit from being described differently per branch, a note whose source PR another line already published takes that published wording verbatim (joined on the trailing `(#N)`, which always names the original source PR). Only the text is reused; the category, the `by @handle` credit, and the `(#N)` are this cut's own. - Release lines consulted: `9.1`, `9.0`, `8.1`, `8.0`, `7.2`, `7.0`, `6.2`, `6.0`, `5.0`, `4.0`, `3.2`, `3.0`, `2.8`, `2.6`, `2.4`, `2.2` - No note needed its wording replaced. *Generated by valkey-ci-agent. Review before merging into the release line.* Signed-off-by: valkeyrie-bot[bot] <3692572+valkeyrie-bot[bot]@users.noreply.github.com> Co-authored-by: valkeyrie-bot[bot] <3692572+valkeyrie-bot[bot]@users.noreply.github.com>
When the IO threads pool shrinks,
updateIOThreadsunlocks each removed thread's mutex and then callsshutdownIOThread, which unlocks the same mutex again. Unlocking a mutex that isn't locked is undefined behavior.The unlock in
shutdownIOThreadwas added in #2898, but the older one inupdateIOThreadswas never removed. This PR removes it, soshutdownIOThreaddoes the unlock like it does forkillIOThreads.No new test: with default mutexes the second unlock silently succeeds on Linux and macOS, so only error-checking mutexes or TSan would catch it.
tests/unit/io-threads.tclalready covers shrinking the pool.