Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp.web listens both TCP and Unix socket if -U has been supplied #8205

Open
1 task done
eirnym opened this issue Mar 5, 2024 · 4 comments
Open
1 task done

aiohttp.web listens both TCP and Unix socket if -U has been supplied #8205

eirnym opened this issue Mar 5, 2024 · 4 comments
Labels

Comments

@eirnym
Copy link

eirnym commented Mar 5, 2024

Describe the bug

documentation for -U aiohttp.web parameter: Unix file system path to serve on. Specifying a path will cause hostname and port arguments to be ignored.

The aiohttp web argument parser expects that it would be run without -H and -P parameters. Thus default has been passed to argparse. Defaults in argparse works in way that if values has not been specified, they are set anyway. In this situation it works not as intended. The possible solution is to override

Bonus: there may be many hostnames could be provided (as run server accepts), but argument parser is not adapted in this way.

To Reproduce

Let's take very basic aiohttp server implementation from tutorial:

from aiohttp import web

async def hello(request):
    return web.Response(text="Hello, world")


def init_func(argv):
    app = web.Application()
    app.add_routes([web.get('/', hello)])
    return app

and run it:

$ python -m aiohttp.web -U /path/to/socket/file.sock package.module:init_func

Expected behavior

I'm expecting that server is:

  • Listening on localhost:8080 (as documented) if no arguments explicitly provided
  • Listening on hostname:port (as documented) if hostname:port are provided
  • Listening on Unix socket only If Unix socket is provided and hostname isn't explicitly provided (as documented)
  • Listening on Unix socket only (as documented) or both (optional, but desired) If both unix socket and hostname are explicitly provided

Logs/tracebacks

DEBUG:asyncio:Using selector: KqueueSelector
======== Running on http://localhost:8080, http://unix:/path/to/socket/file.sock: ========
(Press CTRL+C to quit)

Python Version

$ python --version
Python 3.12.2

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.9.3
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: /Users/eirnym/Developer/sdk/python/312/iguana/lib/python3.12/site-packages
Requires: aiosignal, attrs, frozenlist, multidict, yarl
Required-by:

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.5
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /Users/eirnym/Developer/sdk/python/312/iguana/lib/python3.12/site-packages
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.9.4
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /Users/eirnym/Developer/sdk/python/312/iguana/lib/python3.12/site-packages
Requires: idna, multidict
Required-by: aiohttp

OS

macOS

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@eirnym eirnym added the bug label Mar 5, 2024
@Dreamsorcerer
Copy link
Member

Feel free to make a PR to fix it. I'm not really sure how useful the aiohttp.web entrypoint even is, I don't think it appears anywhere in our documentation..

@eirnym
Copy link
Author

eirnym commented Mar 7, 2024

it's appears here, just at the beginning of the server documentation. Also parameters are well documented using argparse.

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Mar 7, 2024

Right, that should probably be replaced with a recommendation to use aiohttp-devtools though...

@webknjaz
Copy link
Member

webknjaz commented Apr 1, 2024

Not sure about a recommendation but a note regarding another way would be useful. Many frameworks provide runpy entrypoints so I think it should remain exposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants