You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "masaori335 (via GitHub)" <gi...@apache.org> on 2026/06/25 04:46:27 UTC
[PR] Annotate BRAVO locks for thread-safety analysis [trafficserver]
masaori335 opened a new pull request, #13330:
URL: https://github.com/apache/trafficserver/pull/13330
Enabling -Wthread-safety tree-wide surfaced findings in Bravo.h on macOS, where libc++ marks the underlying std::shared_mutex as a capability: the wrapper acquires and releases it across method boundaries and on fast/slow-path branches the analyzer cannot follow. Fedora CI uses libstdc++, which does not annotate std types, so it never saw these.
Make ts::bravo::shared_mutex_impl a real capability so the contract is checked on every Clang, not papered over on one std lib; its lock-driving bodies are the trusted implementation and stay exempted, matching the ts::shared_mutex pattern. Make the reader guard a rigid scoped capability -- acquire in constructor, release in destructor, no copy/move/defer/release -- which the analysis tracks with no exemption; the movable std::shared_lock-style forms it replaced could not be tracked, and no caller used them. Restructure the unit test's try-lock asserts so the acquire gates a branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Annotate BRAVO locks for thread-safety analysis [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13330:
URL: https://github.com/apache/trafficserver/pull/13330#discussion_r3471948253
##########
include/tsutil/Bravo.h:
##########
@@ -240,16 +174,16 @@ template <typename T = std::shared_mutex, size_t SLOT_SIZE = 256, int SLOWDOWN_G
}
void
- unlock()
+ unlock() TS_RELEASE() TS_NO_THREAD_SAFETY_ANALYSIS
{
_mutex.underlying.unlock();
}
////
- // Shared locking
+ // Shared locking (bodies exempted for the same reason as the exclusive ones above)
//
void
- lock_shared(Token &token)
+ lock_shared(Token &token) TS_ACQUIRE_SHARED() TS_NO_THREAD_SAFETY_ANALYSIS
{
debug_assert(SLOT_SIZE >= DenseThreadId::num_possible_values());
Review Comment:
`lock_shared(Token &token)` only assigns `token` on the fast path. If a caller reuses a `Token` that previously held a non-zero fast-path value and this call takes the slow path (e.g., after `_revoke()` clears `read_bias`), `token` can retain that stale non-zero value. A subsequent `unlock_shared(token)` would then incorrectly take the fast-path slot release and fail to unlock the underlying shared_mutex, potentially deadlocking.
##########
include/tsutil/Bravo.h:
##########
@@ -277,7 +211,7 @@ template <typename T = std::shared_mutex, size_t SLOT_SIZE = 256, int SLOWDOWN_G
}
bool
- try_lock_shared(Token &token)
+ try_lock_shared(Token &token) TS_TRY_ACQUIRE_SHARED(true) TS_NO_THREAD_SAFETY_ANALYSIS
{
debug_assert(SLOT_SIZE >= DenseThreadId::num_possible_values());
Review Comment:
`try_lock_shared(Token &token)` only assigns `token` on the fast path. If the slow path succeeds (or if it fails) and the caller passed a non-zero token from a prior fast-path acquisition, `unlock_shared(token)` can later mis-handle the unlock (treating it as a slot unlock instead of unlocking the underlying mutex). Resetting `token` to 0 on entry makes the slow-path contract explicit and robust.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Annotate BRAVO locks for thread-safety analysis [trafficserver]
Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen commented on PR #13330:
URL: https://github.com/apache/trafficserver/pull/13330#issuecomment-5111249733
Cherry-picked to 10.2.x
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Annotate BRAVO locks for thread-safety analysis [trafficserver]
Posted by "masaori335 (via GitHub)" <gi...@apache.org>.
masaori335 merged PR #13330:
URL: https://github.com/apache/trafficserver/pull/13330
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org