diff --git a/gunicorn/config.py b/gunicorn/config.py index 99b4ba31..5549a372 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -495,11 +495,19 @@ def validate_chdir(val): return path -def validate_address(val): +def validate_statsd_address(val): val = validate_string(val) if val is None: return None + # As of major release 20, util.parse_address would recognize unix:PORT + # as a UDS address, breaking backwards compatibility. We defend against + # that regression here (this is also unit-tested). + # Feel free to remove in the next major release. + unix_hostname_regression = re.match(r'^unix:(\d+)$', val) + if unix_hostname_regression: + return ('unix', int(unix_hostname_regression.group(1))) + try: address = util.parse_address(val, default_port='8125') except RuntimeError: @@ -1473,7 +1481,7 @@ class StatsdHost(Setting): cli = ["--statsd-host"] meta = "STATSD_ADDR" default = None - validator = validate_address + validator = validate_statsd_address desc = """\ The address of the StatsD server to log to. diff --git a/tests/test_config.py b/tests/test_config.py index db33cb3f..e3a3212b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -313,12 +313,23 @@ def test_statsd_host(): assert c.statsd_host == ("localhost", 8125) c.set("statsd_host", "statsd:7777") assert c.statsd_host == ("statsd", 7777) - c.set("statsd_host", "unix:/path/to.sock") + c.set("statsd_host", "unix:///path/to.sock") assert c.statsd_host == "/path/to.sock" pytest.raises(TypeError, c.set, "statsd_host", 666) pytest.raises(TypeError, c.set, "statsd_host", "host:string") +def test_statsd_host_with_unix_as_hostname(): + # This is a regression test for major release 20. After this release + # we should consider modifying the behavior of util.parse_address to + # simplify gunicorn's code + c = config.Config() + c.set("statsd_host", "unix:7777") + assert c.statsd_host == ("unix", 7777) + c.set("statsd_host", "unix://some.socket") + assert c.statsd_host == "some.socket" + + def test_statsd_changes_logger(): c = config.Config() assert c.logger_class == glogging.Logger