microsoft / call-center-ai

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Apache License 2.0
177 stars 53 forks source link

AIOHTTP client issue with async DNS #275

Open elvis-mdevo opened 1 month ago

elvis-mdevo commented 1 month ago

I have just clone the main repository of this project et configure the environment with correct config file. Locally function app start correctly. But an error occur in the console when a make a call.

This happen on your last commit "https://github.com/microsoft/call-center-ai/commit/3241b0e236a75bacf097dd648062a31181020056" =>

Check the log below:

[2024-08-02T15:29:45.627Z] Request URL: 'https://xxxxxx-auth.europe.communication.azure.com/calling/callConnections:answer?api-version=REDACTED'
[2024-08-02T15:29:45.627Z] Request method: 'POST'
[2024-08-02T15:29:45.627Z] Request headers:
[2024-08-02T15:29:45.627Z]     'Content-Type': 'application/json'
[2024-08-02T15:29:45.627Z]     'Content-Length': '8520'
[2024-08-02T15:29:45.627Z]     'Repeatability-First-Sent': 'REDACTED'
[2024-08-02T15:29:45.627Z]     'Repeatability-Request-ID': 'REDACTED'
[2024-08-02T15:29:45.627Z]     'Accept': 'application/json'
[2024-08-02T15:29:45.627Z]     'x-ms-client-request-id': '0c05eab0-50e4-xxxxxxxxxxxxxa-00155da425e3'
[2024-08-02T15:29:45.627Z]     'User-Agent': 'azsdk-python-communication-callautomation/1.2.0 Python/3.11.9 (Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.39)'
[2024-08-02T15:29:45.627Z]     'x-ms-date': 'REDACTED'
[2024-08-02T15:29:45.627Z]     'x-ms-content-sha256': 'REDACTED'
[2024-08-02T15:29:45.627Z]     'x-ms-return-client-request-id': 'true'
[2024-08-02T15:29:45.627Z]     'Authorization': 'REDACTED'
[2024-08-02T15:29:45.627Z]     'traceparent': '00-7fbb1db4c1b725bc3b5b64ca37d828d-01'
[2024-08-02T15:29:45.627Z] A body is sent with the request
[2024-08-02T15:29:50.683Z] Executed 'Functions.call_event' (Failed, Id=f58a724f-8fb0-4aed-952d, Duration=5235ms)
[2024-08-02T15:29:50.683Z] System.Private.CoreLib: Exception while executing function: Functions.call_event. System.Private.CoreLib: Result: Failure
[2024-08-02T15:29:50.683Z] Exception: ServiceRequestError: Cannot connect to host cs-xxxxxxxxxxxxxxxxxxxx-auth.europe.communication.azure.com:443 ssl:default [None]
[2024-08-02T15:29:50.683Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 602, in _handle__invocation_request
[2024-08-02T15:29:50.683Z]     await self._run_async_func(fi_context, fi.func, args)
[2024-08-02T15:29:50.684Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 939, in _run_async_func
[2024-08-02T15:29:50.684Z]     return await ExtensionManager.get_async_invocation_wrapper(
[2024-08-02T15:29:50.684Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.684Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/extension.py", line 147, in get_async_invocation_wrapper
[2024-08-02T15:29:50.684Z]     result = await function(**args)
[2024-08-02T15:29:50.684Z]              ^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.684Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/opentelemetry/util/_decorator.py", line 68, in async_wrapper
[2024-08-02T15:29:50.684Z]     return await func(*args, **kwargs)  # type: ignore
[2024-08-02T15:29:50.684Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.684Z]   File "/mnt/main-call-center-ai/function_app.py", line 385, in call_event
[2024-08-02T15:29:50.684Z]     await on_new_call(
[2024-08-02T15:29:50.684Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/opentelemetry/util/_decorator.py", line 68, in async_wrapper
[2024-08-02T15:29:50.684Z]     return await func(*args, **kwargs)  # type: ignore
[2024-08-02T15:29:50.684Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.684Z]   File "/mnt/c/main-call-center-ai/helpers/call_events.py", line 49, in on_new_call
[2024-08-02T15:29:50.684Z]     answer_call_result = await client.answer_call(
[2024-08-02T15:29:50.684Z]                          ^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/tracing/decorator_async.py", line 105, in wrapper_use_tracer
[2024-08-02T15:29:50.685Z]     return await func(*args, **kwargs)
[2024-08-02T15:29:50.685Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/communication/callautomation/aio/_call_automation_client_async.py", line 308, in answer_call
[2024-08-02T15:29:50.685Z]     result = await self._client.answer_call(
[2024-08-02T15:29:50.685Z]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/tracing/decorator_async.py", line 105, in wrapper_use_tracer
[2024-08-02T15:29:50.685Z]     return await func(*args, **kwargs)
[2024-08-02T15:29:50.685Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/communication/callautomation/_generated/aio/operations/_operations.py", line 267, in answer_call
[2024-08-02T15:29:50.685Z]     pipeline_response: PipelineResponse = await self._client._pipeline.run(  # type: ignore # pylint: disable=protected-access
[2024-08-02T15:29:50.685Z]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 219, in run
[2024-08-02T15:29:50.685Z]     return await first_node.send(pipeline_request)
[2024-08-02T15:29:50.685Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.685Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.685Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.685Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.685Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.685Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.685Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   [Previous line repeated 2 more times]
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/policies/_redirect_async.py", line 73, in send
[2024-08-02T15:29:50.685Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.685Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/policies/_retry_async.py", line 206, in send
[2024-08-02T15:29:50.685Z]     raise err
[2024-08-02T15:29:50.685Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/policies/_retry_async.py", line 180, in send
[2024-08-02T15:29:50.686Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.686Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.686Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.686Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.686Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.686Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.686Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.686Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.686Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 68, in send
[2024-08-02T15:29:50.686Z]     response = await self.next.send(request)
[2024-08-02T15:29:50.686Z]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.686Z]   [Previous line repeated 3 more times]
[2024-08-02T15:29:50.686Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/_base_async.py", line 104, in send
[2024-08-02T15:29:50.686Z]     await self._sender.send(request.http_request, **request.context.options),
[2024-08-02T15:29:50.686Z]     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-08-02T15:29:50.686Z]   File "/home/.pyenv/versions/callcenterai/lib/python3.11/site-packages/azure/core/pipeline/transport/_aiohttp.py", line 348, in send
[2024-08-02T15:29:50.686Z]     raise ServiceRequestError(err, error=err) from err
[2024-08-02T15:29:50.686Z] .
[2024-08-02T15:29:52.507Z] Executing 'Functions.call_event' (Reason='New queue message detected on 'call-33805981322'.', Id=54de6a89-e4bd-xxxxxxxxx-8562-c91e952bfaf5)
elvis-mdevo commented 1 month ago

The problem come from helpers/http.py in line 50. When we comment this line (TCPConnector), the above error never exist.

async def aiohttp_session() -> ClientSession:
    """
    Create an AIOHTTP session.

    Object is cached for performance.

    Returns a `ClientSession` instance.
    """
    global _session  # pylint: disable=global-statement
    if not _session:
        _session = ClientSession(
            # Same config as default in the SDK
            auto_decompress=False,
            cookie_jar=await _aiohttp_cookie_jar(),
            trust_env=False,
            # Performance
            #connector=TCPConnector(resolver=AsyncResolver()),
            # Reliability
            timeout=ClientTimeout(
                connect=5,
                total=60,
            ),
        )
    return _session

@clemlesne Please could you check this on your side ?

clemlesne commented 4 days ago

I confirmed it works well on my computer (macOS Sequoia 15.0), a VM (Ubuntu 24.04) and the demo instance (deployed on Azure).

I would need more details from your environment and a reproduction steps to fix that or to justify removing that piece of code (which plays an important role in lowering network calls latencies).