Skip to content

Commit 2b09ecb

Browse files
authored
Makes health checks flexible so they don't tear down connections under heavy load (#328)
Adds error::write_timeout close #104
1 parent da09787 commit 2b09ecb

26 files changed

+868
-404
lines changed

example/cpp20_chat_room.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/asio/consign.hpp>
1111
#include <boost/asio/detached.hpp>
1212
#include <boost/asio/posix/stream_descriptor.hpp>
13+
#include <boost/asio/read_until.hpp>
1314
#include <boost/asio/redirect_error.hpp>
1415
#include <boost/asio/signal_set.hpp>
1516

example/cpp20_echo_server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <boost/asio/co_spawn.hpp>
1010
#include <boost/asio/consign.hpp>
1111
#include <boost/asio/detached.hpp>
12+
#include <boost/asio/read_until.hpp>
1213
#include <boost/asio/redirect_error.hpp>
1314
#include <boost/asio/signal_set.hpp>
1415

include/boost/redis/config.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct config {
8383
*/
8484
std::optional<int> database_index = 0;
8585

86-
/// Message used by the health-checker in @ref boost::redis::basic_connection::async_run.
86+
/// Message used by `PING` commands sent by the health checker.
8787
std::string health_check_id = "Boost.Redis";
8888

8989
/**
@@ -105,7 +105,24 @@ struct config {
105105
std::chrono::steady_clock::duration ssl_handshake_timeout = std::chrono::seconds{10};
106106

107107
/** @brief Time span between successive health checks.
108-
* Set to zero to disable health-checks pass zero as duration.
108+
* Set to zero to disable health-checks.
109+
*
110+
* When this value is set to a non-zero duration, @ref basic_connection::async_run
111+
* will issue `PING` commands whenever no command is sent to the server for more
112+
* than `health_check_interval`. You can configure the message passed to the `PING`
113+
* command using @ref health_check_id.
114+
*
115+
* Enabling health checks also sets timeouts to individual network
116+
* operations. The connection is considered dead if:
117+
*
118+
* @li No byte can be written to the server after `health_check_interval`.
119+
* @li No byte is read from the server after `2 * health_check_interval`.
120+
*
121+
* If the health checker finds that the connection is unresponsive, it will be closed,
122+
* and a reconnection will be triggered, as if a network error had occurred.
123+
*
124+
* The exact timeout values are *not* part of the interface, and might change
125+
* in future versions.
109126
*/
110127
std::chrono::steady_clock::duration health_check_interval = std::chrono::seconds{2};
111128

0 commit comments

Comments
 (0)