Skip to content

Commit 54422b6

Browse files
committed
stability fix
1 parent b96cfae commit 54422b6

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
int main(int argc, char *argv[])
1717
{
1818
#ifdef __cpp_lib_format
19-
std::cout << std::format("{} version 20241026\n", app_name);
19+
std::cout << std::format("{} version 20241027\n", app_name);
2020
if (argc <= 1)
2121
{
2222
std::cout << std::format("Usage: {} config1.conf\n", app_name);
2323
std::cout << std::format(" {} config1.conf config2.conf...\n", (int)app_name.length(), app_name.data());
2424
return 0;
2525
}
2626
#else
27-
std::cout << app_name << " version 20241026\n";
27+
std::cout << app_name << " version 20241027\n";
2828
if (argc <= 1)
2929
{
3030
std::cout << "Usage: " << app_name << " config1.conf\n";

src/networks/client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,11 @@ void client_mode::cleanup_expiring_forwarders()
499499
int64_t time_elapsed = calculate_difference(time_right_now, expire_time);
500500

501501
if (time_elapsed > CLEANUP_WAITS / 3 &&
502-
time_elapsed <= CLEANUP_WAITS / 3 * 2 &&
502+
time_elapsed <= CLEANUP_WAITS * 2 / 3 &&
503503
forwarder_ptr != nullptr)
504504
forwarder_ptr->pause(true);
505505

506-
if (time_elapsed > CLEANUP_WAITS / 3 * 2 &&
506+
if (time_elapsed > CLEANUP_WAITS * 2 / 3 &&
507507
forwarder_ptr != nullptr)
508508
forwarder_ptr->stop();
509509

src/networks/connections.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void udp_server::handle_receive(std::unique_ptr<uint8_t[]> buffer_cache, const a
344344
{
345345
if (error)
346346
{
347-
if (!connection_socket.is_open())
347+
if (error == asio::error::operation_aborted || !connection_socket.is_open())
348348
return;
349349
}
350350

@@ -396,6 +396,9 @@ void udp_client::pause(bool set_as_pause)
396396

397397
void udp_client::stop()
398398
{
399+
bool expect = true;
400+
if (stopped.compare_exchange_strong(expect, true))
401+
return;
399402
stopped.store(true);
400403
callback = empty_udp_callback;
401404
if (connection_socket.is_open())
@@ -544,7 +547,10 @@ void udp_client::start_receive()
544547

545548
std::unique_ptr<uint8_t[]> buffer_cache = std::make_unique<uint8_t[]>(BUFFER_SIZE);
546549
uint8_t *buffer_raw_ptr = buffer_cache.get();
547-
connection_socket.async_receive_from(asio::buffer(buffer_raw_ptr, BUFFER_SIZE), incoming_endpoint,
550+
auto asio_buffer = asio::buffer(buffer_raw_ptr, BUFFER_SIZE);
551+
if (!connection_socket.is_open())
552+
return;
553+
connection_socket.async_receive_from(asio_buffer, incoming_endpoint,
548554
[buffer = std::move(buffer_cache), this](const asio::error_code &error, std::size_t bytes_transferred) mutable
549555
{
550556
handle_receive(std::move(buffer), error, bytes_transferred);
@@ -555,7 +561,7 @@ void udp_client::handle_receive(std::unique_ptr<uint8_t[]> buffer_cache, const a
555561
{
556562
if (error)
557563
{
558-
if (!stopped.load() && !paused.load() && connection_socket.is_open())
564+
if (error != asio::error::operation_aborted && !stopped.load() && !paused.load() && connection_socket.is_open())
559565
start_receive();
560566
return;
561567
}

src/networks/relay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ void relay_mode::cleanup_expiring_data_connections()
748748
std::shared_ptr<forwarder> egress_forwarder = std::atomic_load(&udp_session_ptr->egress_forwarder);
749749

750750
if (time_elapsed > CLEANUP_WAITS / 3 &&
751-
time_elapsed <= CLEANUP_WAITS / 3 * 2 &&
751+
time_elapsed <= CLEANUP_WAITS * 2 / 3 &&
752752
egress_forwarder != nullptr)
753753
egress_forwarder->pause(true);
754754

755-
if (time_elapsed > CLEANUP_WAITS / 3 * 2 &&
755+
if (time_elapsed > CLEANUP_WAITS * 2 / 3 &&
756756
egress_forwarder != nullptr)
757757
egress_forwarder->stop();
758758

0 commit comments

Comments
 (0)