Skip to content

Commit d07c78d

Browse files
committed
fix: addition of a few protections to prevent certain data races
1 parent 44bd22a commit d07c78d

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

include/dpp/queues.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,18 @@ class DPP_EXPORT http_request {
229229
/**
230230
* @brief True if request has been made.
231231
*/
232-
bool completed;
232+
std::atomic<bool> completed;
233233

234234
/**
235235
* @brief True for requests that are not going to discord (rate limits code skipped).
236236
*/
237237
bool non_discord;
238238

239+
/**
240+
* @brief Client mutex
241+
*/
242+
std::mutex cli_mutex;
243+
239244
/**
240245
* @brief HTTPS client
241246
*/

src/dpp/cluster/timer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ bool cluster::stop_timer(timer t) {
5757
void cluster::tick_timers() {
5858
time_t now = time(nullptr);
5959

60-
if (next_timer.empty()) {
61-
return;
60+
{
61+
std::lock_guard<std::mutex> l(timer_guard);
62+
if (next_timer.empty()) {
63+
return;
64+
}
6265
}
6366
do {
6467
timer_t cur_timer;

src/dpp/queues.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ http_request_completion_t http_request::run(request_concurrency_queue* processor
225225
}
226226
http_connect_info hci = https_client::get_host_info(_host);
227227
try {
228-
cli = std::make_unique<https_client>(
228+
std::unique_ptr<https_client> tmp = std::make_unique<https_client>(
229229
owner,
230230
hci.hostname,
231231
hci.port,
@@ -286,6 +286,10 @@ http_request_completion_t http_request::run(request_concurrency_queue* processor
286286
});
287287
}
288288
);
289+
{
290+
std::lock_guard<std::mutex> client(this->cli_mutex);
291+
cli = std::move(tmp);
292+
}
289293
}
290294
catch (const std::exception& e) {
291295
owner->log(ll_error, "HTTP(S) error on " + hci.scheme + " connection to " + hci.hostname + ":" + std::to_string(hci.port) + ": " + std::string(e.what()));

src/dpp/socketengines/epoll.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct DPP_EXPORT socket_engine_epoll : public socket_engine_base {
135135

136136
if ((eh->flags & WANT_DELETION) != 0L) {
137137
remove_socket(fd);
138+
std::lock_guard<std::shared_mutex> lg(this->fds_mutex);
138139
fds.erase(fd);
139140
}
140141
}

0 commit comments

Comments
 (0)