From 04ea46027289d986d38199ef93a4a0940f7540a8 Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Thu, 13 Nov 2014 16:04:06 +0100 Subject: [PATCH] Use oslo.utils.netutils function to set tcp_keepalive Use netutils.set_tcp_keepalive to set tcp keepalive parameters. In addition to the existing conf option for tcp_keepidle, new values were added for tcp_keepalive (to turn on/off this feature, tcp_keepalive_interval (to specify gap between successive probes) and tcp_keepalive_count (to specify number of probes). Change-Id: I60c3bbf5f3deff8bdffe97af76052386e4598b45 --- manila/wsgi.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/manila/wsgi.py b/manila/wsgi.py index 3c610a181a..69a0e0ce25 100644 --- a/manila/wsgi.py +++ b/manila/wsgi.py @@ -30,6 +30,7 @@ import eventlet import eventlet.wsgi import greenlet from oslo.config import cfg +from oslo.utils import netutils from paste import deploy import routes.middleware import six @@ -46,10 +47,20 @@ socket_opts = [ default=4096, help="Number of backlog requests to configure the socket " "with."), + cfg.BoolOpt('tcp_keepalive', + default=True, + help="Sets the value of TCP_KEEPALIVE (True/False) for each " + "server socket."), cfg.IntOpt('tcp_keepidle', default=600, help="Sets the value of TCP_KEEPIDLE in seconds for each " "server socket. Not supported on OS X."), + cfg.IntOpt('tcp_keepalive_interval', + help="Sets the value of TCP_KEEPINTVL in seconds for each " + "server socket. Not supported on OS X."), + cfg.IntOpt('tcp_keepalive_count', + help="Sets the value of TCP_KEEPCNT for each " + "server socket. Not supported on OS X."), cfg.StrOpt('ssl_ca_file', default=None, help="CA certificate file to use to verify " @@ -177,14 +188,13 @@ class Server(object): "after trying for 30 seconds") % {'host': host, 'port': port}) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - # sockets can hang around forever without keepalive - sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) - # This option isn't available in the OS X version of eventlet - if hasattr(socket, 'TCP_KEEPIDLE'): - sock.setsockopt(socket.IPPROTO_TCP, - socket.TCP_KEEPIDLE, - CONF.tcp_keepidle) + # sockets can hang around forever without keepalive + netutils.set_tcp_keepalive(sock, + CONF.tcp_keepalive, + CONF.tcp_keepidle, + CONF.tcp_keepalive_interval, + CONF.tcp_keepalive_count) return sock