Posted on

Azure App Service: Resolving SNAT Port Exhaustion via Auto-Heal

How to Configure a “Healing” Rule

If your application experiences performance degradation or connectivity issues due to saturated sockets, you can configure Auto-Heal to monitor and restart the process before the app becomes unreachable:

  1. Access the Portal: Go to your App Service in the Azure Portal.

  2. Navigation: In the left-hand menu, select “Diagnose and solve problems”.

  3. Tools: Select “Diagnostic Tools” and then click on “Auto-Heal”.

  4. Define Conditions: Choose “Request Count”.

    • Example: Set it to 2000 requests within a 10-minute interval (or a value significantly higher than your average traffic).

  5. Configure Actions: Select “Recycle”.

  6. Finalize: Click “Save” to apply the rule.

By setting this up, Azure will monitor the traffic patterns. If it detects an anomalous spike (which often precedes a socket lockout), it will automatically recycle the worker process to clear the connection table.


How to Remove an “Auto-Heal” Rule

Once the root cause (such as a non-singleton CosmosClient) is fixed, you may want to disable the automated recycling:

  1. Locate the tool: Navigate back to Diagnose and solve problems > Auto-Heal.

  2. Toggle Off: You will see a main toggle at the top (usually labeled “Enable Auto-Heal”).

  3. Disable: Switch the toggle to Off (or Disabled). This immediately deactivates all saved rules.

  4. Confirm: Remember to click “Save” at the bottom of the page to apply the changes.