You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ch...@apache.org on 2021/09/04 00:19:15 UTC

[pulsar] 03/05: Avoid throwing exceptions when setting socket option (#11329)

This is an automated email from the ASF dual-hosted git repository.

chenhang pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit a2d2757bc4e67be2012846bc767c7ad4dc2314c7
Author: Yunze Xu <xy...@163.com>
AuthorDate: Thu Jul 15 21:23:48 2021 +0800

    Avoid throwing exceptions when setting socket option (#11329)
    
    (cherry picked from commit ac8194f2f46b39566b410fc4c5db750110ade8a1)
---
 pulsar-client-cpp/lib/ClientConnection.cc | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/pulsar-client-cpp/lib/ClientConnection.cc b/pulsar-client-cpp/lib/ClientConnection.cc
index 0411b2f..43f358f 100644
--- a/pulsar-client-cpp/lib/ClientConnection.cc
+++ b/pulsar-client-cpp/lib/ClientConnection.cc
@@ -378,20 +378,37 @@ void ClientConnection::handleTcpConnected(const boost::system::error_code& err,
         }
         state_ = TcpConnected;
         connectTimeoutTask_->stop();
-        socket_->set_option(tcp::no_delay(true));
 
-        socket_->set_option(tcp::socket::keep_alive(true));
+        boost::system::error_code error;
+        socket_->set_option(tcp::no_delay(true), error);
+        if (error) {
+            LOG_WARN(cnxString_ << "Socket failed to set tcp::no_delay: " << error.message());
+        }
+
+        socket_->set_option(tcp::socket::keep_alive(true), error);
+        if (error) {
+            LOG_WARN(cnxString_ << "Socket failed to set tcp::socket::keep_alive: " << error.message());
+        }
 
         // Start TCP keep-alive probes after connection has been idle after 1 minute. Ideally this
         // should never happen, given that we're sending our own keep-alive probes (within the TCP
         // connection) every 30 seconds
-        socket_->set_option(tcp_keep_alive_idle(1 * 60));
+        socket_->set_option(tcp_keep_alive_idle(1 * 60), error);
+        if (error) {
+            LOG_DEBUG(cnxString_ << "Socket failed to set tcp_keep_alive_idle: " << error.message());
+        }
 
         // Send up to 10 probes before declaring the connection broken
-        socket_->set_option(tcp_keep_alive_count(10));
+        socket_->set_option(tcp_keep_alive_count(10), error);
+        if (error) {
+            LOG_DEBUG(cnxString_ << "Socket failed to set tcp_keep_alive_count: " << error.message());
+        }
 
         // Interval between probes: 6 seconds
-        socket_->set_option(tcp_keep_alive_interval(6));
+        socket_->set_option(tcp_keep_alive_interval(6), error);
+        if (error) {
+            LOG_DEBUG(cnxString_ << "Socket failed to set tcp_keep_alive_interval: " << error.message());
+        }
 
         if (tlsSocket_) {
             if (!isTlsAllowInsecureConnection_) {