{"record":{"id":"d01d42ba8d80bb11","repo":"python/cpython","slug":"multiple-exceptions","errorCode":null,"errorMessage":"Multiple exceptions: {}","messagePattern":"Multiple exceptions: (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1182,"sourceCode":"                    happy_eyeballs_delay,\n                    loop=self,\n                ))[0]  # can't use sock, _, _ as it keeks a reference to exceptions\n\n            if sock is None:\n                exceptions = [exc for sub in exceptions for exc in sub]\n                try:\n                    if all_errors:\n                        raise ExceptionGroup(\"create_connection failed\", exceptions)\n                    if len(exceptions) == 1:\n                        raise exceptions[0]\n                    elif exceptions:\n                        # If they all have the same str(), raise one.\n                        model = str(exceptions[0])\n                        if all(str(exc) == model for exc in exceptions):\n                            raise exceptions[0]\n                        # Raise a combined exception so the user can see all\n                        # the various error messages.\n                        raise OSError('Multiple exceptions: {}'.format(\n                            ', '.join(str(exc) for exc in exceptions)))\n                    else:\n                        # No exceptions were collected, raise a timeout error\n                        raise TimeoutError('create_connection failed')\n                finally:\n                    exceptions = None\n\n        else:\n            if sock is None:\n                raise ValueError(\n                    'host and port was not specified and no sock specified')\n            if sock.type != socket.SOCK_STREAM:\n                # We allow AF_INET, AF_INET6, AF_UNIX as long as they\n                # are SOCK_STREAM.\n                # We support passing AF_UNIX sockets even though we have\n                # a dedicated API for that: create_unix_connection.\n                # Disallowing AF_UNIX in this method, breaks backwards\n                # compatibility.","sourceCodeStart":1164,"sourceCodeEnd":1200,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L1164-L1200","documentation":"An OSError raised by create_connection (all_errors=False path) when multiple addresses were tried and all failed with different error strings. asyncio first tries to re-raise a single exception if there was only one attempt or all messages are identical; when they differ, it joins them into one OSError whose message is 'Multiple exceptions: ...' so the user can see every failure reason.","triggerScenarios":"Connecting to a dual-stack host where the IPv6 attempt times out and the IPv4 attempt gets 'connection refused' — two distinct messages, so the combined OSError is raised. Only reachable with all_errors=False (pre-3.12 default).","commonSituations":"Partial reachability (v6 blocked, v4 refused), mixed DNS/timeout failures across multiple A records, flaky uplinks during address iteration.","solutions":["Parse or log the full message to see each underlying failure and fix the dominant one (often the first).","Pass all_errors=True to get a structured ExceptionGroup instead of a string-joined message.","Retry with backoff for transient network conditions once causes are known."],"exampleFix":"// before\ntry:\n    await loop.create_connection(proto, host, port)\nexcept OSError as e:\n    print(e)  # opaque 'Multiple exceptions: ...'\n\n// after\ntry:\n    await loop.create_connection(proto, host, port, all_errors=True)\nexcept* OSError as eg:\n    for exc in eg.exceptions:\n        print(repr(exc))  # individual causes","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    tp, pr = await loop.create_connection(proto, host, port, all_errors=False)\nexcept OSError as e:\n    if str(e).startswith('Multiple exceptions:'):\n        for part in str(e).split(', '):\n            log.warning(f'connect failure: {part}')\n    raise","preventionTips":["Prefer all_errors=True for structured multi-failure handling.","Log the full message text — the joined causes identify which address family failed.","Wrap connection setup in retry-with-backoff at the service layer."],"tags":["asyncio","network","oserror","multi-address","connection"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}