Skip to content

Commit

Permalink
Add configurable tcp keepalive support enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dtucny committed Dec 24, 2012
1 parent 45be9c2 commit 6ad642a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions conf/minion
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,32 @@
#
# The list of services to restart after a successful update. Empty by default.
#update_restart_services: []


###### Keepalive settings ######
############################################
# ZeroMQ now includes support for configuring SO_KEEPALIVE if supported by
# the OS. If connections between the minion and the master pass through
# a state tracking device such as a firewall or VPN gateway, there is
# the risk that it could tear down the connection the master and minion
# without informing either party that their connection has been taken away.
# Enabling TCP Keepalives prevents this from happening.
#
# Overall state of TCP Keepalives, enable (1 or True), disable (0 or False)
# or leave to the OS defaults (-1), on linux, typically disabled. Default True, enabled.
#tcp_keepalive: True
#
# How long before the first keepalive should be sent in seconds. Default -1
# to use OS defaults, typically 7200 seconds on Linux see
# /proc/sys/net/ipv4/tcp_keepalive_time.
#tcp_keepalive_idle: -1
#
# How many lost probes are needed to consider the connection lost. Default -1
# to use OS defaults, typically 9 on Linux, see /proc/sys/net/ipv4/tcp_keepalive_probes.
#tcp_keepalive_cnt: -1
#
# How often, in seconds, to send keepalives after the first one. Default -1 to
# use OS defaults, typically 75 seconds on Linux, see
# /proc/sys/net/ipv4/tcp_keepalive_intvl.
#tcp_keepalive_intvl: -1

4 changes: 4 additions & 0 deletions salt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def minion_config(path, check_dns=True):
'recon_max': 5000,
'win_repo_cachefile': 'salt://win/repo/winrepo.p',
'pidfile': '/var/run/salt-minion.pid',
'tcp_keepalive': True,
'tcp_keepalive_idle': 300,
'tcp_keepalive_cnt': -1,
'tcp_keepalive_intvl': -1,
}

if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
Expand Down
5 changes: 5 additions & 0 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,11 @@ def tune_in(self):
self.socket.setsockopt(
zmq.RECONNECT_IVL_MAX, self.opts['recon_max']
)
if hasattr(zmq, 'TCP_KEEPALIVE'):
self.socket.setsockopt(zmq.TCP_KEEPALIVE, self.opts['tcp_keepalive'])
self.socket.setsockopt(zmq.TCP_KEEPALIVE_IDLE, self.opts['tcp_keepalive_idle'])
self.socket.setsockopt(zmq.TCP_KEEPALIVE_CNT, self.opts['tcp_keepalive_cnt'])
self.socket.setsockopt(zmq.TCP_KEEPALIVE_INTVL, self.opts['tcp_keepalive_intvl'])
self.socket.connect(self.master_pub)
self.poller.register(self.socket, zmq.POLLIN)
self.epoller.register(self.epull_sock, zmq.POLLIN)
Expand Down

0 comments on commit 6ad642a

Please sign in to comment.