Skip to content

Commit d8510c4

Browse files
committed
FIX | bug in gRPC Timer Object
1 parent bbd29dd commit d8510c4

5 files changed

Lines changed: 27 additions & 13 deletions

File tree

include/cache/ManapiTL.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ namespace manapi {
3232
void iput (const K &key, V &&value, std::chrono::milliseconds duration) {
3333
this->cleanup();
3434
auto id = std::make_pair(std::chrono::steady_clock::now() + duration, std::forward<decltype(value)>(value));
35-
auto it = this->m_data.insert({key, id});
36-
if (!it.second) {
37-
this->m_sorted.erase(std::make_pair(it.first->second.first, it.first->first));
38-
it.first->second = id;
35+
auto it = this->m_data.find(key);
36+
if (it != this->m_data.end()) {
37+
this->m_sorted.erase(std::make_pair(it->second.first, it->first));
3938
}
39+
it = this->m_data.insert_or_assign(std::move(key), std::move(id)).first;
4040
try {
41-
this->m_sorted.insert(std::make_pair(id.first, it.first->first));
41+
this->m_sorted.insert(std::make_pair(it->second.first, it->first));
4242
}
4343
catch (...) {
44-
this->m_data.erase(it.first);
44+
this->m_data.erase(it);
4545
std::rethrow_exception(std::current_exception());
4646
}
4747
}

include/ext/pq/AsyncPostgreImpl.ipp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ manapi::future<manapi::status_or<manapi::ext::pq::item>> manapi::ext::pq::db::ma
378378
co_return status_not_found("db:not found");
379379
}
380380

381+
bool manapi::ext::pq::db::has_master() const {
382+
return !!this->m_master;
383+
}
384+
385+
bool manapi::ext::pq::db::has_slaves() const {
386+
return !!this->m_slaves.size();
387+
}
388+
381389
manapi::future<manapi::ext::pq::status_or<manapi::ext::pq::result>> manapi::ext::pq::db::pexec(ktypes type, const char *command, int nParams, const Oid *paramTypes, const char * const *paramValues, const int *paramLengths,const int *paramFormats, ctoken token) {
382390
while (true) {
383391
auto wrk_res = type == kMaster ? (co_await this->master()) :(co_await this->slave());

include/ext/pq/AsyncPostgrePool.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ namespace manapi::ext::pq {
105105

106106
future<manapi::status_or<item>> master ();
107107

108+
bool has_master () const;
109+
110+
bool has_slaves () const;
111+
108112
template<typename ...Args>
109113
manapi::future<pq::status_or<pq::result>> exec (ktypes type, const std::string &sql, Args &&...args) {
110114
std::string buffer;

src/ManapiGrpc.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#if MANAPIHTTP_GRPC_DEPENDENCY
1717

1818
#include <grpcpp/grpcpp.h>
19+
#include <grpc/event_engine/event_engine.h>
1920

2021
enum manapi_grpc_endpoint_flags {
2122
MANAPI_GRPC_ENDPOINT_WANT_READ = 1,
@@ -1251,10 +1252,11 @@ grpc_event_engine::experimental::EventEngine::TaskHandle manapi::net::wgrpc::eve
12511252

12521253
auto rhs = ctx->timerpool()->append_timer_sync(ms,
12531254
[td] (manapi::timer timer) -> void {
1254-
try { td->closure->Run(); }
1255+
auto closure = std::move(td->closure);
1256+
task_handle_cancel(manapi::async::current().get(), td->index);
1257+
try { closure->Run(); }
12551258
catch (std::exception const &e) { manapi_log_error("%s:%s failed due to %s",
12561259
"wgrpc", "gRPC send a error", e.what()); }
1257-
task_handle_cancel(manapi::async::current().get(), td->index);
12581260
});
12591261

12601262
*timer = rhs.unwrap();
@@ -1349,10 +1351,11 @@ grpc_event_engine::experimental::EventEngine::TaskHandle manapi::net::wgrpc::eve
13491351

13501352
auto rhs = ctx->timerpool()->append_timer_sync(ms,
13511353
[td] (manapi::timer timer) mutable -> void {
1352-
try { td->closure (); }
1354+
auto closure = std::move(td->closure);
1355+
task_handle_cancel(manapi::async::current().get(), td->index);
1356+
try { closure (); }
13531357
catch (std::exception const &e) { manapi_log_error(
13541358
"%s:%s failed due to %s", "wgrpc", "gRPC send a error", e.what()); }
1355-
task_handle_cancel(manapi::async::current().get(), td->index);
13561359
});
13571360

13581361
*timer = rhs.unwrap();

src/worker/ManapiTcp.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ manapi::net::worker::shared_conn manapi::net::worker::TCP::accept (const ev::sha
355355
connection->wrk.flags |= WRK_INTERFACE_CONN_RETRY;
356356
}
357357

358-
auto res = it->second.insert({reinterpret_cast<uintptr_t>(connection.get()),
359-
connection});
360-
assert((res.second));
358+
auto res = it->second.insert_or_assign(reinterpret_cast<uintptr_t>(connection.get()),
359+
connection);
361360
}
362361
catch (std::exception const &e) {
363362
manapi_log_error("tcp accept: failed due to %s", e.what());

0 commit comments

Comments
 (0)