Skip to content

Commit

Permalink
async http: make copy of url and payload for thread safety
Browse files Browse the repository at this point in the history
- originally passed by reference
  • Loading branch information
astibal committed Jun 4, 2024
1 parent b05a1f0 commit ed1e8b7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/service/http/async_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ namespace sx::http {

static bool emit_url(std::string const& url, std::string const& pay, reply_hook const& hook) {
auto &pool = ThreadPool::instance::get();
auto ret = pool.enqueue([url, pay, hook]([[maybe_unused]] std::atomic_bool const &stop_flag) {
emit_url_wait(url, pay, hook);

// add extra safety and copy values, to make them copyable in thread lambda capture
std::string copy_url(url);
std::string copy_pay(pay);

auto ret = pool.enqueue([copy_url, copy_pay, hook]([[maybe_unused]] std::atomic_bool const &stop_flag) {

emit_url_wait(copy_url, copy_pay, hook);
});

return (ret > 0);
Expand Down

0 comments on commit ed1e8b7

Please sign in to comment.