Skip to content

Commit

Permalink
crimson/osd: fix the lifetime of Notify during timeouts.
Browse files Browse the repository at this point in the history
This fixes a segfault during `LibRadosWatchNotify.WatchNotify2Timeout`.

Signed-off-by: Radoslaw Zarzynski <[email protected]>
  • Loading branch information
rzarzynski committed Apr 8, 2021
1 parent 116ef52 commit aa4c902
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/crimson/osd/watch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ void Notify::do_timeout()
if (complete) {
return;
}
// it might be that `this` is kept alive only because of the reference
// a watcher stores and which is being removed by `cancel_notify()`.
// to avoid use-after-free we bump up the ref counter with `guard_ptr`.
[[maybe_unused]] auto guard_ptr = shared_from_this();
for (auto& watcher : watchers) {
watcher->cancel_notify(ninfo.notify_id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/watch.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct notify_reply_t {
};
std::ostream &operator<<(std::ostream &out, const notify_reply_t &rhs);

class Notify {
class Notify : public seastar::enable_shared_from_this<Notify> {
std::set<WatchRef> watchers;
const notify_info_t ninfo;
crimson::net::ConnectionRef conn;
Expand Down

0 comments on commit aa4c902

Please sign in to comment.