config = hypercorn.config.Config()
config.bind = ["0.0.0.0:8088"] # OK
config.bind = ["[::]:8088"] # OK
config.bind = ["0.0.0.0:8088", "[::]:8088"] # OSError: [Errno 98] Address already in use
asyncio.run(hypercorn.asyncio.serve(endpoints.app, config))
The earlier listens on IPv4 only.
The variant in the middle actually listens on both IPv4 and IPv6 on my linux machine.
https://pgjones.gitlab.io/hypercorn/how_to_guides/binds.html seems to suggest the latter, but hypercorn fails with this hairy traceback:
[2022-10-11 10:03:29 +0900] [39335] [INFO] Running on http://0.0.0.0:8088 (CTRL + C to quit)
unhandled exception during asyncio.run() shutdown
task: <Task finished name='Task-2' coro=<Lifespan.handle_lifespan() done, defined at venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py:31> exception=LifespanFailureError('Lifespan failure in shutdown. \'Traceback (most recent call last):\n File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run\n return loop.run_until_complete(main)\n File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete\n return future.result()\n File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/__init__.py", line 49, in serve\n await worker_serve(\n File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 120, in worker_serve\n await asyncio.start_server(_server_callback, backlog=config.backlog, sock=sock)\n File "/usr/lib/python3.10/asyncio/streams.py", line 84, in start_server\n return await loop.create_server(factory, host, port, **kwds)\n File "/usr/lib/python3.10/asyncio/base_events.py", line 1526, in create_server\n server._start_serving()\n File "/usr/lib/python3.10/asyncio/base_events.py", line 318, in _start_serving\n sock.listen(self._backlog)\nOSError: [Errno 98] Address already in use\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "venv-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 648, in lifespan\n await receive()\n File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py", line 92, in asgi_receive\n return await self.app_queue.get()\n File "/usr/lib/python3.10/asyncio/queues.py", line 159, in get\n await getter\nasyncio.exceptions.CancelledError\n\'')>
Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/__init__.py", line 49, in serve
await worker_serve(
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 120, in worker_serve
await asyncio.start_server(_server_callback, backlog=config.backlog, sock=sock)
File "/usr/lib/python3.10/asyncio/streams.py", line 84, in start_server
return await loop.create_server(factory, host, port, **kwds)
File "/usr/lib/python3.10/asyncio/base_events.py", line 1526, in create_server
server._start_serving()
File "/usr/lib/python3.10/asyncio/base_events.py", line 318, in _start_serving
sock.listen(self._backlog)
OSError: [Errno 98] Address already in use
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "venv-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 648, in lifespan
await receive()
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py", line 92, in asgi_receive
return await self.app_queue.get()
File "/usr/lib/python3.10/asyncio/queues.py", line 159, in get
await getter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py", line 43, in handle_lifespan
await self.app(
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 33, in __call__
await self.app(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 270, in __call__
await super().__call__(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 149, in __call__
await self.app(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 51, in __call__
await self.app(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "venv-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 669, in __call__
await self.lifespan(scope, receive, send)
File "venv-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 652, in lifespan
await send({"type": "lifespan.shutdown.failed", "message": exc_text})
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py", line 104, in asgi_send
raise LifespanFailureError("shutdown", message["message"])
hypercorn.utils.LifespanFailureError: Lifespan failure in shutdown. 'Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/__init__.py", line 49, in serve
await worker_serve(
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 120, in worker_serve
await asyncio.start_server(_server_callback, backlog=config.backlog, sock=sock)
File "/usr/lib/python3.10/asyncio/streams.py", line 84, in start_server
return await loop.create_server(factory, host, port, **kwds)
File "/usr/lib/python3.10/asyncio/base_events.py", line 1526, in create_server
server._start_serving()
File "/usr/lib/python3.10/asyncio/base_events.py", line 318, in _start_serving
sock.listen(self._backlog)
OSError: [Errno 98] Address already in use
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "venv-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 648, in lifespan
await receive()
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/lifespan.py", line 92, in asgi_receive
return await self.app_queue.get()
File "/usr/lib/python3.10/asyncio/queues.py", line 159, in get
await getter
asyncio.exceptions.CancelledError
'
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "venvuth/__main__.py", line 59, in <module>
asyncio.run(hypercorn.asyncio.serve(endpoints.app, config))
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/__init__.py", line 49, in serve
await worker_serve(
File "venv-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/run.py", line 120, in worker_serve
await asyncio.start_server(_server_callback, backlog=config.backlog, sock=sock)
File "/usr/lib/python3.10/asyncio/streams.py", line 84, in start_server
return await loop.create_server(factory, host, port, **kwds)
File "/usr/lib/python3.10/asyncio/base_events.py", line 1526, in create_server
server._start_serving()
File "/usr/lib/python3.10/asyncio/base_events.py", line 318, in _start_serving
sock.listen(self._backlog)
OSError: [Errno 98] Address already in use
So, well, I understand why this is happening, but the experience is a bit overwhelming... I feel that issues like this is why I keep seeing binds to 0.0.0.0
from junior developers.