Skip to content

Commit

Permalink
include/seastar/core/gate: re-enable gate debug and handle race condi…
Browse files Browse the repository at this point in the history
…tion

when using crimson multi core, gate debugging may hit race condition
when releaseing holdes and using auto_unlink.

Signed-off-by: NitzanMordhai <[email protected]>
  • Loading branch information
NitzanMordhai committed Jul 30, 2024
1 parent e7a2679 commit 527568b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/seastar/core/gate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
#endif

#ifdef SEASTAR_DEBUG
// See: https://tracker.ceph.com/issues/64332
// #define SEASTAR_GATE_HOLDER_DEBUG
#define SEASTAR_GATE_HOLDER_DEBUG
#endif

namespace seastar {
Expand All @@ -62,6 +61,7 @@ SEASTAR_MODULE_EXPORT
class gate {
size_t _count = 0;
std::optional<promise<>> _stopped;
std::mutex _lock_gate;

#ifdef SEASTAR_GATE_HOLDER_DEBUG
void assert_not_held_when_moved() const noexcept;
Expand Down Expand Up @@ -89,6 +89,7 @@ public:
return *this;
}
~gate() {
std::lock_guard lock(_lock_gate);
assert(!_count && "gate destroyed with outstanding requests");
assert_not_held_when_destroyed();
}
Expand Down Expand Up @@ -171,18 +172,22 @@ public:
/// Moving the \ref gate::holder is supported and has no effect on the \c gate itself.
class holder {
gate* _g;

#ifdef SEASTAR_GATE_HOLDER_DEBUG
using member_hook_t = boost::intrusive::list_member_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>;
member_hook_t _link;

void debug_hold_gate() noexcept {
if (_g) {
std::lock_guard lock_gate(_g->_lock_gate);
_g->_holders.push_back(*this);
}
}

void debug_release_gate() noexcept {
_link.unlink();
if (_link.is_linked()) {
_link.unlink();
}
}
#else // SEASTAR_GATE_HOLDER_DEBUG
void debug_hold_gate() noexcept {}
Expand All @@ -194,6 +199,7 @@ public:
gate* release_gate() noexcept {
auto* g = std::exchange(_g, nullptr);
if (g) {
std::lock_guard lock_holder(g->_lock_gate);
debug_release_gate();
}
return g;
Expand Down

0 comments on commit 527568b

Please sign in to comment.