diff --git a/library/cpp/sandesh_session.cc b/library/cpp/sandesh_session.cc index b6ab3c21..6977ebda 100644 --- a/library/cpp/sandesh_session.cc +++ b/library/cpp/sandesh_session.cc @@ -287,6 +287,7 @@ SandeshSession::SandeshSession(TcpServer *client, Socket *socket, keepalive_idle_time_(kSessionKeepaliveIdleTime), keepalive_interval_(kSessionKeepaliveInterval), keepalive_probes_(kSessionKeepaliveProbes), + tcp_user_timeout_(kSessionTcpUserTimeout), reader_task_id_(reader_task_id) { if (Sandesh::role() == Sandesh::SandeshRole::Collector) { send_buffer_queue_.reset(new Sandesh::SandeshBufferQueue(writer_task_id, @@ -340,7 +341,7 @@ boost::system::error_code SandeshSession::SetSocketOptions() { return ec; } return SetSocketKeepaliveOptions(keepalive_idle_time_, keepalive_interval_, - keepalive_probes_); + keepalive_probes_, tcp_user_timeout_); } void SandeshSession::OnRead(Buffer buffer) { diff --git a/library/cpp/sandesh_session.h b/library/cpp/sandesh_session.h index 57644d27..3faaceb9 100644 --- a/library/cpp/sandesh_session.h +++ b/library/cpp/sandesh_session.h @@ -219,9 +219,10 @@ class SandeshSession : public TcpSession { friend class SandeshSessionTest; // 60 seconds - 45s + (3*5)s - static const int kSessionKeepaliveIdleTime = 45; // in seconds + static const int kSessionKeepaliveIdleTime = 15; // in seconds static const int kSessionKeepaliveInterval = 3; // in seconds static const int kSessionKeepaliveProbes = 5; // count + static const int kSessionTcpUserTimeout = 30000; // ms bool SendMsg(Sandesh *sandesh); bool SendBuffer(boost::shared_ptr sbuffer); @@ -238,6 +239,7 @@ class SandeshSession : public TcpSession { int keepalive_idle_time_; int keepalive_interval_; int keepalive_probes_; + int tcp_user_timeout_; int reader_task_id_; // Session statistics diff --git a/library/python/pysandesh/sandesh_session.py b/library/python/pysandesh/sandesh_session.py index d1595122..100fe8d7 100644 --- a/library/python/pysandesh/sandesh_session.py +++ b/library/python/pysandesh/sandesh_session.py @@ -228,9 +228,11 @@ def _send(self, send_buf): class SandeshSession(TcpSession): - _KEEPALIVE_IDLE_TIME = 45 # in secs + _KEEPALIVE_IDLE_TIME = 15 # in secs _KEEPALIVE_INTERVAL = 3 # in secs _KEEPALIVE_PROBES = 5 + _TCP_USER_TIMEOUT_OPT = 18 + _TCP_USER_TIMEOUT_VAL = 30000 # ms def __init__(self, sandesh_instance, server, event_handler, sandesh_msg_handler): @@ -299,6 +301,12 @@ def _set_socket_options(self): if hasattr(socket, 'TCP_KEEPCNT'): self._socket.setsockopt( socket.IPPROTO_TCP, socket.TCP_KEEPCNT, self._KEEPALIVE_PROBES) + try: + self._socket.setsockopt(socket.IPPROTO_TCP, + self._TCP_USER_TIMEOUT_OPT, self._TCP_USER_TIMEOUT_VAL) + except: + self._logger.error('setsockopt failed: option %d, value %d' % + (self._TCP_USER_TIMEOUT_OPT, self._TCP_USER_TIMEOUT_VAL)) # end _set_socket_options # Private functions