Rev 6162: Expose --client-timeout to the command line, pass it through the layers. in http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797
John Arbash Meinel
john at arbash-meinel.com
Thu Sep 15 12:56:38 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797
------------------------------------------------------------
revno: 6162
revision-id: john at arbash-meinel.com-20110915125623-sxo3jk6d858alyzf
parent: john at arbash-meinel.com-20110915124145-72vwotn932ukd0x2
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: drop-idle-connections-824797
timestamp: Thu 2011-09-15 14:56:23 +0200
message:
Expose --client-timeout to the command line, pass it through the layers.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2011-09-08 12:29:08 +0000
+++ b/bzrlib/builtins.py 2011-09-15 12:56:23 +0000
@@ -5184,6 +5184,8 @@
'option leads to global uncontrolled write access to your '
'file system.'
),
+ Option('client-timeout', type=float,
+ help='Override the default idle client timeout (5min).'),
]
def get_host_and_port(self, port):
@@ -5206,7 +5208,7 @@
return host, port
def run(self, port=None, inet=False, directory=None, allow_writes=False,
- protocol=None):
+ protocol=None, client_timeout=None):
from bzrlib import transport
if directory is None:
directory = os.getcwd()
@@ -5217,7 +5219,10 @@
if not allow_writes:
url = 'readonly+' + url
t = transport.get_transport(url)
- protocol(t, host, port, inet)
+ try:
+ protocol(t, host, port, inet, client_timeout)
+ except TypeError:
+ protocol(t, host, port, inet)
class cmd_join(Command):
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py 2011-09-15 12:03:23 +0000
+++ b/bzrlib/smart/server.py 2011-09-15 12:56:23 +0000
@@ -349,9 +349,10 @@
transport = _mod_transport.get_transport_from_url(expand_userdirs.get_url())
self.transport = transport
- def _make_smart_server(self, host, port, inet):
- c = config.GlobalStack()
- timeout = c.get('server.client_timeout')
+ def _make_smart_server(self, host, port, inet, timeout):
+ if timeout is None:
+ c = config.GlobalStack()
+ timeout = c.get('server.client_timeout')
if inet:
smart_server = medium.SmartServerPipeStreamMedium(
sys.stdin, sys.stdout, self.transport)
@@ -381,16 +382,16 @@
ui.ui_factory = ui.SilentUIFactory()
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
- def set_up(self, transport, host, port, inet):
+ def set_up(self, transport, host, port, inet, timeout):
self._make_backing_transport(transport)
- self._make_smart_server(host, port, inet)
+ self._make_smart_server(host, port, inet, timeout)
self._change_globals()
def tear_down(self):
for cleanup in reversed(self.cleanups):
cleanup()
-def serve_bzr(transport, host=None, port=None, inet=False):
+def serve_bzr(transport, host=None, port=None, inet=False, timeout=None):
"""This is the default implementation of 'bzr serve'.
It creates a TCP or pipe smart server on 'transport, and runs it. The
@@ -399,7 +400,7 @@
"""
bzr_server = BzrServerFactory()
try:
- bzr_server.set_up(transport, host, port, inet)
+ bzr_server.set_up(transport, host, port, inet, timeout)
bzr_server.smart_server.serve()
except:
hook_caught_exception = False
=== modified file 'bzrlib/tests/blackbox/test_serve.py'
--- a/bzrlib/tests/blackbox/test_serve.py 2011-09-15 12:06:11 +0000
+++ b/bzrlib/tests/blackbox/test_serve.py 2011-09-15 12:56:23 +0000
@@ -286,6 +286,22 @@
# Now, we wait for timeout to trigger
self.assertServerFinishesCleanly(process)
+ def test_bzr_serve_supports_client_timeout(self):
+ process, url = self.start_server_port(['--client-timeout=0.1'])
+ self.build_tree_contents([('a_file', 'contents\n')])
+ # We can connect and issue a request
+ t = transport.get_transport_from_url(url)
+ self.assertEqual('contents\n', t.get_bytes())
+ # However, if we just wait for more content from the server, it will
+ # eventually disconnect us.
+ # TODO: Use something like signal.alarm() so that if the server doesn't
+ # properly handle the timeout, we end up failing the test instead
+ # of hanging forever.
+ m = t.get_smart_medium()
+ m.read_bytes()
+ # Now, we wait for timeout to trigger
+ self.assertServerFinishesCleanly(process)
+
class TestCmdServeChrooting(TestBzrServeBase):
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-09-15 10:10:11 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-09-15 12:56:23 +0000
@@ -74,7 +74,9 @@
* ``bzr serve`` will now disconnect clients if they have not issued an RPC
request after 5minutes. On POSIX platforms, this will also happen for
- ``bzr serve --inet``. (John Arbash Meinel, #824797)
+ ``bzr serve --inet``. This can be overridden with the configuration
+ variable ``serve.client_timeout`` or in the command line parameter
+ ``bzr serve --client-timeout=X``. (John Arbash Meinel, #824797)
* ``config.Option`` can now declare ``default_from_env``, a list of
environment variables to get a default value from. (Vincent Ladeuil)
@@ -233,6 +235,11 @@
* New registry ``OptionRegistry`` specialized for configuration options.
(Vincent Ladeuil)
+* Plugins that implement custom protocols for ``bzr serve`` should now
+ also take an argument ``timeout``. This is used by the the bzr protocol
+ to close a connection if a client has been idle for more than X seconds.
+ (Default 5minutes). (John Arbash Meinel)
+
* Remove ``AtomicFile.closed`` which has been deprecated in bzr 0.10.
(Vincent Ladeuil)
More information about the bazaar-commits
mailing list