Skip to content

Commit 7ebc1b8

Browse files
committed
rgw: Watch/Notify memory leak fix maybe!
Signed-off-by: Adam C. Emerson <[email protected]>
1 parent e0c4ef0 commit 7ebc1b8

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

src/neorados/RADOS.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ class Notifier : public async::service_list_base_hook {
13731373
};
13741374

13751375
asio::io_context::executor_type ex;
1376+
Objecter::LingerOp* linger_op;
13761377
// Zero for unbounded. I would not recommend this.
13771378
const uint32_t capacity;
13781379

@@ -1383,14 +1384,18 @@ class Notifier : public async::service_list_base_hook {
13831384
uint64_t next_id = 0;
13841385

13851386
void service_shutdown() {
1387+
if (linger_op) {
1388+
linger_op->put();
1389+
}
13861390
std::unique_lock l(m);
13871391
handlers.clear();
13881392
}
13891393

13901394
public:
13911395

1392-
Notifier(asio::io_context::executor_type ex, uint32_t capacity)
1393-
: ex(ex), capacity(capacity),
1396+
Notifier(asio::io_context::executor_type ex, Objecter::LingerOp* linger_op,
1397+
uint32_t capacity)
1398+
: ex(ex), linger_op(linger_op), capacity(capacity),
13941399
svc(asio::use_service<async::service<Notifier>>(
13951400
asio::query(ex, boost::asio::execution::context))) {
13961401
// register for service_shutdown() notifications
@@ -1507,7 +1512,11 @@ void RADOS::watch_(Object o, IOContext _ioc,
15071512
linger_op, op, ioc->snapc, ceph::real_clock::now(), bl,
15081513
asio::bind_executor(
15091514
std::move(e),
1510-
[c = std::move(c), cookie](bs::error_code e, cb::list) mutable {
1515+
[c = std::move(c), cookie, linger_op](bs::error_code e, cb::list) mutable {
1516+
if (e) {
1517+
linger_op->objecter->linger_cancel(linger_op);
1518+
cookie = 0;
1519+
}
15111520
asio::dispatch(asio::append(std::move(c), e, cookie));
15121521
}), nullptr);
15131522
}
@@ -1525,7 +1534,7 @@ void RADOS::watch_(Object o, IOContext _ioc, WatchComp c,
15251534
uint64_t cookie = linger_op->get_cookie();
15261535
// Shared pointer to avoid a potential race condition
15271536
linger_op->user_data.emplace<std::shared_ptr<Notifier>>(
1528-
std::make_shared<Notifier>(get_executor(), queue_size));
1537+
std::make_shared<Notifier>(get_executor(), linger_op, queue_size));
15291538
auto& n = ceph::any_cast<std::shared_ptr<Notifier>&>(
15301539
linger_op->user_data);
15311540
linger_op->handle = std::ref(*n);
@@ -1537,7 +1546,12 @@ void RADOS::watch_(Object o, IOContext _ioc, WatchComp c,
15371546
linger_op, op, ioc->snapc, ceph::real_clock::now(), bl,
15381547
asio::bind_executor(
15391548
std::move(e),
1540-
[c = std::move(c), cookie](bs::error_code e, cb::list) mutable {
1549+
[c = std::move(c), cookie, linger_op](bs::error_code e, cb::list) mutable {
1550+
if (e) {
1551+
linger_op->user_data.reset();
1552+
linger_op->objecter->linger_cancel(linger_op);
1553+
cookie = 0;
1554+
}
15411555
asio::dispatch(asio::append(std::move(c), e, cookie));
15421556
}), nullptr);
15431557
}
@@ -1610,9 +1624,7 @@ void RADOS::unwatch_(uint64_t cookie, IOContext _ioc,
16101624
[objecter = impl->objecter,
16111625
linger_op, c = std::move(c)]
16121626
(bs::error_code ec) mutable {
1613-
if (!ec) {
1614-
objecter->linger_cancel(linger_op);
1615-
}
1627+
objecter->linger_cancel(linger_op);
16161628
asio::dispatch(asio::append(std::move(c), ec));
16171629
}));
16181630
}

src/osdc/Objecter.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ void Objecter::_send_linger_ping(LingerOp *info)
729729

730730
Op *o = new Op(info->target.base_oid, info->target.base_oloc,
731731
std::move(opv), info->target.flags | CEPH_OSD_FLAG_READ,
732-
fu2::unique_function<Op::OpSig>{CB_Linger_Ping(this, info, now)},
732+
CB_Linger_Ping(this, info, now),
733733
nullptr, nullptr);
734734
o->target = info->target;
735735
o->should_resend = false;
@@ -757,7 +757,7 @@ void Objecter::_linger_ping(LingerOp *info, bs::error_code ec, ceph::coarse_mono
757757
ec = _normalize_watch_error(ec);
758758
info->last_error = ec;
759759
if (info->handle) {
760-
asio::defer(finish_strand, CB_DoWatchError(this, info, ec));
760+
asio::post(finish_strand, CB_DoWatchError(this, info, ec));
761761
}
762762
}
763763
} else {

src/osdc/Objecter.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ class Objecter : public md_config_obs_t, public Dispatcher {
20632063
}
20642064

20652065
Op(const object_t& o, const object_locator_t& ol, osdc_opvec&& _ops,
2066-
int f, OpComp&& fin, version_t *ov, int *offset = nullptr,
2066+
int f, OpComp fin, version_t *ov, int *offset = nullptr,
20672067
ZTracer::Trace *parent_trace = nullptr) :
20682068
target(o, ol, f),
20692069
ops(std::move(_ops)),
@@ -2103,26 +2103,6 @@ class Objecter : public md_config_obs_t, public Dispatcher {
21032103
}
21042104
}
21052105

2106-
Op(const object_t& o, const object_locator_t& ol, osdc_opvec&& _ops,
2107-
int f, fu2::unique_function<OpSig>&& fin, version_t *ov, int *offset = nullptr,
2108-
ZTracer::Trace *parent_trace = nullptr) :
2109-
target(o, ol, f),
2110-
ops(std::move(_ops)),
2111-
out_bl(ops.size(), nullptr),
2112-
out_handler(ops.size()),
2113-
out_rval(ops.size(), nullptr),
2114-
out_ec(ops.size(), nullptr),
2115-
onfinish(std::move(fin)),
2116-
objver(ov),
2117-
data_offset(offset) {
2118-
if (target.base_oloc.key == o)
2119-
target.base_oloc.key.clear();
2120-
if (parent_trace && parent_trace->valid()) {
2121-
trace.init("op", nullptr, parent_trace);
2122-
trace.event("start");
2123-
}
2124-
}
2125-
21262106
bool operator<(const Op& other) const {
21272107
return tid < other.tid;
21282108
}

0 commit comments

Comments
 (0)