Search code examples
springazuredockernetwork-programmingcontainers

Communation between two Azure Container App return 502 Bad Gateway. How to fix it?


I have two Azure container apps (app1, app2) in one container environment. In the container apps spring applications are running. I try to make a REST request from app1 to app2 but I am getting this response:

502 Bad Gateway upstream connect error or disconnect/reset before headers. retried and the latest reset reason: protocol error. 

The error is happening between app1 and app2. When app1 is called it starts executing the code but app2 answers with this error.

When I run app1 on my local environment and call app2 via azure public url it works without any problems. It also works when I run both apps in a local docker container. But from the moment I app1 is running in the azure container environment I get the error. I tried to call app2 from app1 via the public url and also inside the container env via "http://app2". Both does not work. I also tried multiple approaches to do the rest call in app1 (ProxyExchange, RestTemplate Exchange, RestTemplate get, OpenFeign). Nothing changes.


Solution

  • Firstly implement a health checks as you already checked logs, in both app1 and app2 to ensure that the applications are running and healthy.

    Verify that the DNS resolution is working correctly within the Azure Container Apps environment. Ensure that app1 can resolve the DNS of app2 and vice versa.

    Check if there are any NSG, firewalls, or Azure Container Apps environment configurations that might be blocking the communication between the containers.

    check if app1 is trying to connect to the correct endpoint of app2. and finally confirm that the applications are listening on the correct ports, and the communication between them is using the expected protocols (HTTP/HTTPS).

    if none of these solves I suggest you to raise a support req in azure portal illgive you the link below,

    https://portal.azure.com/#view/Microsoft_Azure_Support/NewSupportRequestV3Blade/callerWorkflowId/5fa9c255-970f-4d06-b697-fbfef6943245/callerName/Microsoft_Azure_Support%2FHelpAndSupportOverview.ReactView