Skip to content

Commit

Permalink
[coro_io] fix memory leak when io_context stopped before start.
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jul 13, 2023
1 parent 21030e4 commit b08e2de
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/ylt/coro_io/io_context_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class io_context_pool {
work_.clear();

if (ok) {
// clear all unfinished work
for (auto &e : io_contexts_) {
e->run();
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/ylt/coro_rpc/impl/coro_rpc_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class coro_rpc_server_base {
}

void close_acceptor() {
asio::dispatch(acceptor_.get_executor(), [this]() {
asio::post(acceptor_.get_executor(), [this]() {
asio::error_code ec;
acceptor_.cancel(ec);
acceptor_.close(ec);
Expand Down
2 changes: 1 addition & 1 deletion src/coro_http/examples/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main() {
"http://www.baidu.com"};
auto chan = coro_io::channel<coro_http_client>::create(
hosts, coro_io::channel<coro_http_client>::channel_config{
.pool_config{.max_connection_ = 1000}});
.pool_config{.max_connection = 1000}});

for (int i = 0, lim = std::thread::hardware_concurrency() * 10; i < lim; ++i)
test_async_channel(chan).start([](auto &&) {
Expand Down
2 changes: 1 addition & 1 deletion src/coro_rpc/examples/base_examples/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main() {
auto worker_cnt = std::thread::hardware_concurrency() * 20;
auto chan = coro_io::channel<coro_rpc_client>::create(
hosts, coro_io::channel<coro_rpc_client>::channel_config{
.pool_config{.max_connection_ = worker_cnt}});
.pool_config{.max_connection = worker_cnt}});
auto chan_ptr = std::make_shared<decltype(chan)>(std::move(chan));
for (int i = 0; i < worker_cnt; ++i) {
call_echo(chan_ptr, 10000).start([](auto &&) {
Expand Down
2 changes: 1 addition & 1 deletion src/coro_rpc/examples/base_examples/client_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main() {
auto client_pool = coro_io::client_pool<coro_rpc_client>::create(
"localhost:8801",
coro_io::client_pool<coro_rpc_client>::pool_config{
.max_connection_ = thread_cnt * 20,
.max_connection = thread_cnt * 20,
.client_config = {.timeout_duration = std::chrono::seconds{50}}});

for (int i = 0, lim = thread_cnt * 20; i < lim; ++i) {
Expand Down

0 comments on commit b08e2de

Please sign in to comment.