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))