Merge "Add client_socket_timeout option"
This commit is contained in:
commit
5769444666
@ -173,6 +173,15 @@ Not supported on OS X.
|
||||
|
||||
Optional. Default: ``600``
|
||||
|
||||
* ``client_socket_timeout=SECONDS``
|
||||
|
||||
Timeout for client connections' socket operations. If an incoming
|
||||
connection is idle for this period it will be closed. A value of `0`
|
||||
means wait forever.
|
||||
|
||||
Optional. Default: ``900``
|
||||
|
||||
|
||||
* ``workers=PROCESSES``
|
||||
|
||||
Number of Glance API or Registry worker processes to start. Each worker
|
||||
|
@ -31,6 +31,11 @@ backlog = 4096
|
||||
# Not supported on OS X.
|
||||
#tcp_keepidle = 600
|
||||
|
||||
# Timeout (in seconds) for client connections' socket operations. If an incoming
|
||||
# connection is idle for this period it will be closed. A value of "0"
|
||||
# means wait forever.
|
||||
#client_socket_timeout = 900
|
||||
|
||||
# API to use for accessing data. Default value points to sqlalchemy
|
||||
# package, it is also possible to use: glance.db.registry.api
|
||||
# data_api = glance.db.sqlalchemy.api
|
||||
|
@ -25,6 +25,11 @@ backlog = 4096
|
||||
# Not supported on OS X.
|
||||
#tcp_keepidle = 600
|
||||
|
||||
# Timeout (in seconds) for client connections' socket operations. If an incoming
|
||||
# connection is idle for this period it will be closed. A value of "0"
|
||||
# means wait forever.
|
||||
#client_socket_timeout = 900
|
||||
|
||||
# API to use for accessing data. Default value points to sqlalchemy
|
||||
# package.
|
||||
#data_api = glance.db.sqlalchemy.api
|
||||
|
@ -99,6 +99,11 @@ eventlet_opts = [
|
||||
'read successfully by the client, you simply have to '
|
||||
'set this option to False when you create a wsgi '
|
||||
'server.')),
|
||||
cfg.IntOpt('client_socket_timeout', default=900,
|
||||
help=_('Timeout for client connections\' socket operations. '
|
||||
'If an incoming connection is idle for this number of '
|
||||
'seconds it will be closed. A value of \'0\' means '
|
||||
'wait forever.')),
|
||||
]
|
||||
|
||||
profiler_opts = [
|
||||
@ -367,6 +372,7 @@ class Server(object):
|
||||
:param has changed: callable to determine if a parameter has changed
|
||||
"""
|
||||
eventlet.wsgi.MAX_HEADER_LINE = CONF.max_header_line
|
||||
self.client_socket_timeout = CONF.client_socket_timeout or None
|
||||
self.configure_socket(old_conf, has_changed)
|
||||
if self.initialize_glance_store:
|
||||
initialize_glance_store()
|
||||
@ -451,7 +457,8 @@ class Server(object):
|
||||
log=self._wsgi_logger,
|
||||
custom_pool=self.pool,
|
||||
debug=False,
|
||||
keepalive=CONF.http_keepalive)
|
||||
keepalive=CONF.http_keepalive,
|
||||
socket_timeout=self.client_socket_timeout)
|
||||
except socket.error as err:
|
||||
if err[0] != errno.EINVAL:
|
||||
raise
|
||||
@ -467,7 +474,8 @@ class Server(object):
|
||||
eventlet.wsgi.server(sock, application, custom_pool=self.pool,
|
||||
log=self._wsgi_logger,
|
||||
debug=False,
|
||||
keepalive=CONF.http_keepalive)
|
||||
keepalive=CONF.http_keepalive,
|
||||
socket_timeout=self.client_socket_timeout)
|
||||
|
||||
def configure_socket(self, old_conf=None, has_changed=None):
|
||||
"""
|
||||
|
66
glance/tests/functional/test_wsgi.py
Normal file
66
glance/tests/functional/test_wsgi.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Tests for `glance.wsgi`."""
|
||||
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
|
||||
from glance.common import wsgi
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestWSGIServer(testtools.TestCase):
|
||||
"""WSGI server tests."""
|
||||
def test_client_socket_timeout(self):
|
||||
CONF.set_default("workers", 0)
|
||||
CONF.set_default("client_socket_timeout", 0.1)
|
||||
"""Verify connections are timed out as per 'client_socket_timeout'"""
|
||||
greetings = 'Hello, World!!!'
|
||||
|
||||
def hello_world(env, start_response):
|
||||
start_response('200 OK', [('Content-Type', 'text/plain')])
|
||||
return [greetings]
|
||||
|
||||
server = wsgi.Server()
|
||||
server.start(hello_world, 0)
|
||||
port = server.sock.getsockname()[1]
|
||||
sock1 = socket.socket()
|
||||
sock1.connect(("127.0.0.1", port))
|
||||
|
||||
fd = sock1.makefile('rw')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
|
||||
buf = fd.read()
|
||||
# Should succeed - no timeout
|
||||
self.assertTrue(re.search(greetings, buf))
|
||||
|
||||
sock2 = socket.socket()
|
||||
sock2.connect(("127.0.0.1", port))
|
||||
time.sleep(0.2)
|
||||
|
||||
fd = sock2.makefile('rw')
|
||||
fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
||||
fd.flush()
|
||||
|
||||
buf = fd.read()
|
||||
# Should fail - connection timed out so we get nothing from the server
|
||||
self.assertFalse(buf)
|
@ -508,7 +508,8 @@ class ServerTest(test_utils.BaseTestCase):
|
||||
log=server._wsgi_logger,
|
||||
debug=False,
|
||||
custom_pool=server.pool,
|
||||
keepalive=False)
|
||||
keepalive=False,
|
||||
socket_timeout=900)
|
||||
|
||||
|
||||
class TestHelpers(test_utils.BaseTestCase):
|
||||
|
@ -136,6 +136,7 @@ class OptsTestCase(utils.BaseTestCase):
|
||||
'digest_algorithm',
|
||||
'http_keepalive',
|
||||
'disabled_notifications',
|
||||
'client_socket_timeout'
|
||||
]
|
||||
|
||||
self._check_opt_groups(opt_list, expected_opt_groups)
|
||||
@ -186,6 +187,7 @@ class OptsTestCase(utils.BaseTestCase):
|
||||
'config_file',
|
||||
'digest_algorithm',
|
||||
'http_keepalive',
|
||||
'client_socket_timeout'
|
||||
]
|
||||
|
||||
self._check_opt_groups(opt_list, expected_opt_groups)
|
||||
|
Loading…
Reference in New Issue
Block a user