python / cpython

The Python programming language
https://www.python.org
Other
63.47k stars 30.39k forks source link

Supply dual-stack (IPv4/IPv6) socket bind routine #69853

Open jaraco opened 8 years ago

jaraco commented 8 years ago
BPO 25667
Nosy @gpshead, @jaraco, @pitrou, @bitdancer, @jleedev
PRs
  • python/cpython#17851
  • Superseder
  • bpo-17561: Add socket.bind_socket() convenience function
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['3.7', 'type-feature', 'library'] title = 'Supply dual-stack (IPv4/IPv6) socket bind routine' updated_at = user = 'https://github.com/jaraco' ``` bugs.python.org fields: ```python activity = actor = 'jaraco' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'jaraco' dependencies = [] files = [] hgrepos = [] issue_num = 25667 keywords = ['patch'] message_count = 5.0 messages = ['254895', '254900', '261317', '286354', '331942'] nosy_count = 5.0 nosy_names = ['gregory.p.smith', 'jaraco', 'pitrou', 'r.david.murray', 'jleedev'] pr_nums = ['17851'] priority = 'normal' resolution = 'duplicate' stage = 'patch review' status = 'open' superseder = '17561' type = 'enhancement' url = 'https://bugs.python.org/issue25667' versions = ['Python 3.7'] ```

    jaraco commented 8 years ago

    When binding to a socket for creating a service, the socket API provides a mechanism for selecting only IPv4 or IPv6, but the simple operation of binding to all interfaces in a dual-stack environment is not easy, as is revealed in bpo-20215 and bpo-24209, but also in third-party packages. I ran into this during the implementation of aiosmtpd (https://gitlab.com/python-smtpd-hackers/aiosmtpd). As a long time maintainer of CherryPy, I've enjoyed the dual stack support there.

    I propose the Python stdlib provide a routine to facilitate this need more generally, and then invoke that implementation to address these other use-cases.

    As it is a new feature, a backports package should be created to supply the same functionality for older Pythons.

    Would this effort require a PEP? Is there a good place for such a routine (maybe socketserver)? Any other thoughts?

    bitdancer commented 8 years ago

    I don't think it should require a PEP, it looks like a fairly straightforward small enhancement. What is the reason to not put it in the socket module?

    jaraco commented 8 years ago

    No reason not to put it in the socket module. I was thinking originally that the socket module was C only, but on further reflection, it could easily be one of the "additional facilities implemented in Python". Great suggestion.

    pitrou commented 7 years ago

    Related though with a different strategy: Tornado's bind_sockets() routine: https://github.com/tornadoweb/tornado/blob/master/tornado/netutil.py#L114-L138

    jaraco commented 5 years ago

    I believe this issue is a duplicate of 17561, which I stumbled onto today.

    lgommans commented 2 years ago

    As jaraco mentioned, I think this can be closed in favor of #61761 unless we want another solution for UDP specifically (because the create_server function in which this was implemented creates a TCP socket only).