From 43ef8e0e5aa5ab89ca0cd595dacbeed662a8bf37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Va=C5=A1ek?= Date: Mon, 17 Nov 2025 16:39:42 +0100 Subject: [PATCH] fixup: issues on IPv4-only machines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej VaĊĦek --- src/func_python/cloudevent.py | 9 ++++++++- src/func_python/http.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/func_python/cloudevent.py b/src/func_python/cloudevent.py index ce9fb21f..5034f776 100644 --- a/src/func_python/cloudevent.py +++ b/src/func_python/cloudevent.py @@ -2,6 +2,7 @@ import logging import os import signal +import socket import hypercorn.config import hypercorn.asyncio @@ -74,7 +75,13 @@ def serve(self): """serve serving this ASGIhandler, delegating implementation of methods as necessary to the wrapped Function instance""" cfg = hypercorn.config.Config() - cfg.bind = [os.getenv('LISTEN_ADDRESS', DEFAULT_LISTEN_ADDRESS)] + + la = os.getenv('LISTEN_ADDRESS', DEFAULT_LISTEN_ADDRESS) + [host, port] = la.rsplit(":", 1) + # fixup for IPv4-only machines + if not socket.has_ipv6 and host == '[::]': + la = "0.0.0.0:" + port + cfg.bind = [la] logging.info(f"function starting on {cfg.bind}") return asyncio.run(self._serve(cfg)) diff --git a/src/func_python/http.py b/src/func_python/http.py index c50862d7..9f47d3e4 100644 --- a/src/func_python/http.py +++ b/src/func_python/http.py @@ -3,6 +3,7 @@ import logging import os import signal +import socket import hypercorn.config import hypercorn.asyncio @@ -69,7 +70,13 @@ def serve(self): """serve serving this ASGIhandler, delegating implementation of methods as necessary to the wrapped Function instance""" cfg = hypercorn.config.Config() - cfg.bind = [os.getenv('LISTEN_ADDRESS', DEFAULT_LISTEN_ADDRESS)] + + la = os.getenv('LISTEN_ADDRESS', DEFAULT_LISTEN_ADDRESS) + [host, port] = la.rsplit(":", 1) + # fixup for IPv4-only machines + if not socket.has_ipv6 and host == '[::]': + la = "0.0.0.0:" + port + cfg.bind = [la] logging.debug(f"function starting on {cfg.bind}") return asyncio.run(self._serve(cfg))