{"record":{"id":"1b4f3f4ab619205c","repo":"RustPython/RustPython","slug":"could-not-bind-on-any-address-out-of-r","errorCode":null,"errorMessage":"could not bind on any address out of %r","messagePattern":"could not bind on any address out of %r","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1640,"sourceCode":"                                        socket.IPV6_V6ONLY,\n                                        True)\n                    try:\n                        sock.bind(sa)\n                    except OSError as err:\n                        msg = ('error while attempting '\n                               'to bind on address %r: %s'\n                               % (sa, str(err).lower()))\n                        if err.errno == errno.EADDRNOTAVAIL:\n                            # Assume the family is not enabled (bpo-30945)\n                            sockets.pop()\n                            sock.close()\n                            if self._debug:\n                                logger.warning(msg)\n                            continue\n                        raise OSError(err.errno, msg) from None\n\n                if not sockets:\n                    raise OSError('could not bind on any address out of %r'\n                                  % ([info[4] for info in infos],))\n\n                completed = True\n            finally:\n                if not completed:\n                    for sock in sockets:\n                        sock.close()\n        else:\n            if sock is None:\n                raise ValueError('Neither host/port nor sock were specified')\n            if sock.type != socket.SOCK_STREAM:\n                raise ValueError(f'A Stream Socket was expected, got {sock!r}')\n            sockets = [sock]\n\n        for sock in sockets:\n            sock.setblocking(False)\n\n        server = Server(self, sockets, protocol_factory,","sourceCodeStart":1622,"sourceCodeEnd":1658,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/asyncio/base_events.py#L1622-L1658","documentation":"Raised by create_server when, after resolving the host(s), no socket could be bound at all - every bind attempt either failed or was skipped as EADDRNOTAVAIL (Lib/asyncio/base_events.py:1640). The message lists all candidate addresses that were tried. It usually means the requested address is not assigned to this machine - most often an IPv6 address on an IPv4-only host, or a hardcoded IP from another environment.","triggerScenarios":"create_server(factory, host='::1', port=8080) on a system without IPv6; host=['10.0.0.5'] where 10.0.0.5 belongs to another machine; every address in a multi-host list failing.","commonSituations":"Hardcoded per-environment IPs drifting between machines; IPv6 enabled in config but disabled in containers/CI; network interfaces not up yet when the service starts during early boot.","solutions":["Bind all interfaces instead: host='' (or '0.0.0.0' / '::')","Verify the address is assigned: ip addr show / ifconfig, or wait for the interface at startup","Remove stale addresses from the host list; keep only addresses present on this host"],"exampleFix":"# before\nserver = await loop.create_server(factory, '10.0.0.5', 8080)\n\n# after\nserver = await loop.create_server(factory, '0.0.0.0', 8080)  # or '' for all families","handlingStrategy":"fallback","validationCode":"import socket\n\ndef local_ips():\n    ips = {'127.0.0.1', '::1'}\n    for target in ('8.8.8.8', '2001:4860:4860::8888'):\n        fam = socket.AF_INET6 if ':' in target else socket.AF_INET\n        s = socket.socket(fam, socket.SOCK_DGRAM)\n        try:\n            s.connect((target, 53))\n            ips.add(s.getsockname()[0])\n        except OSError:\n            pass\n        finally:\n            s.close()\n    return ips\n\nif bind_host not in ('', '*', None) and bind_host not in local_ips():\n    raise ValueError(f'{bind_host!r} is not a local address')","typeGuard":null,"tryCatchPattern":"try:\n    server = await loop.create_server(factory, bind_host, port)\nexcept OSError as e:\n    if 'could not bind on any address' in str(e):\n        logger.warning('%s not bindable; falling back to all interfaces', bind_host)\n        server = await loop.create_server(factory, '', port)\n    else:\n        raise","preventionTips":["Prefer '' (all interfaces) unless a specific address is required","For IPv6 literals, verify the interface exists before binding","Wait for interfaces during early boot instead of crashing"],"tags":["asyncio","tcp","server","bind","ipv6"],"backgroundTag":"bind-failed","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}