From 6a2cbb24c2c1e2a7c9e661a537c065c32d4e4f31 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:39:32 +0100 Subject: [PATCH] rpcdaemon: add ws ping in case of inactivity (#1799) --- silkworm/rpc/ws/connection.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/silkworm/rpc/ws/connection.cpp b/silkworm/rpc/ws/connection.cpp index 8432701261..8a4b80c77e 100644 --- a/silkworm/rpc/ws/connection.cpp +++ b/silkworm/rpc/ws/connection.cpp @@ -44,7 +44,13 @@ Connection::~Connection() { Task Connection::accept(const boost::beast::http::request& req) { // Set suggested timeout settings for the websocket - ws_.set_option(boost::beast::websocket::stream_base::timeout::suggested(boost::beast::role_type::server)); + boost::beast::websocket::stream_base::timeout timeout{ + .handshake_timeout = std::chrono::seconds(30), + .idle_timeout = std::chrono::seconds(60), + .keep_alive_pings = true, + }; + ws_.set_option(timeout); + if (compression_) { boost::beast::websocket::permessage_deflate opt{ .server_enable = true, @@ -58,9 +64,9 @@ Task Connection::accept(const boost::beast::http::request Connection::read_loop() { - try { - SILK_TRACE << "ws::Connection::run starting connection for websocket: " << &ws_; + SILK_TRACE << "ws::Connection::run starting connection for websocket: " << &ws_; + try { while (true) { co_await do_read(); }