Skip to content

Commit

Permalink
fixes for cluster destructor on freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Nov 19, 2024
1 parent 6a36514 commit 276e2ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
9 changes: 2 additions & 7 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,9 @@ cluster::cluster(const std::string &_token, uint32_t _intents, uint32_t _shards,

cluster::~cluster()
{
this->shutdown();
delete rest;
delete raw_rest;
#ifdef _WIN32
WSACleanup();
#endif
this->shutdown();
}

request_queue* cluster::get_rest() {
Expand Down Expand Up @@ -315,7 +312,6 @@ void cluster::shutdown() {
terminating = true;
{
std::lock_guard<std::mutex> l(timer_guard);
log(ll_info, "Terminating " + std::to_string(timer_list.size()) + "timers");
/* Free memory for active timers */
for (auto &t: timer_list) {
delete t.second;
Expand All @@ -325,13 +321,12 @@ void cluster::shutdown() {
}
/* Terminate shards */
for (const auto& sh : shards) {
log(ll_info, "Terminating shard id " + std::to_string(sh.second->shard_id));
delete sh.second;
}
shards.clear();
if (engine_thread) {
engine_thread->join();
}
shards.clear();
}

snowflake cluster::get_dm_channel(snowflake user_id) {
Expand Down
6 changes: 6 additions & 0 deletions src/dpp/socketengines/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ struct socket_engine_poll : public socket_engine_base {
prune();
}

#if _WIN32
~socket_engine_poll() override {
WSACleanup();
}
#endif

bool register_socket(const socket_events& e) final {
bool r = socket_engine_base::register_socket(e);
if (r) {
Expand Down
38 changes: 20 additions & 18 deletions src/dpp/sslclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,26 @@ void ssl_client::read_loop()
owner->socketengine->register_socket(events);
};
setup_events();
timer_handle = owner->start_timer([this, setup_events](auto handle) {
one_second_timer();
if (!tcp_connect_done && time(nullptr) > start + 2 && connect_retries < 3) {
/* Retry failed connect(). This can happen even in the best situation with bullet-proof hosting.
* Previously with blocking connect() there was some leniency in this, but now we have to do this
* ourselves.
*
* Retry up to 3 times, 2 seconds between retries. After this, give up and let timeout code
* take the wheel (will likely end with an exception).
*/
close_socket(sfd);
owner->socketengine->delete_socket(sfd);
ssl_client::connect();
setup_events();
start = time(nullptr) + 2;
connect_retries++;
}
}, 1);
if (!timer_handle) {
timer_handle = owner->start_timer([this, setup_events](auto handle) {
one_second_timer();
if (!tcp_connect_done && time(nullptr) > start + 2 && connect_retries < 3) {
/* Retry failed connect(). This can happen even in the best situation with bullet-proof hosting.
* Previously with blocking connect() there was some leniency in this, but now we have to do this
* ourselves.
*
* Retry up to 3 times, 2 seconds between retries. After this, give up and let timeout code
* take the wheel (will likely end with an exception).
*/
close_socket(sfd);
owner->socketengine->delete_socket(sfd);
ssl_client::connect();
setup_events();
start = time(nullptr) + 2;
connect_retries++;
}
}, 1);
}
}

uint64_t ssl_client::get_bytes_out()
Expand Down

0 comments on commit 276e2ff

Please sign in to comment.