Azure Function occasionally fails because of invalid access to socket

hnnsj 1 Reputation point

I'm running an Azure Function on a consumption plan that has been up and running in production for a couple of years. In the past two-three weeks the function occasionally (but rarely) fails with the following error message:

An attempt was made to access a socket in a way forbidden by its access permissions.

Some research led me to believe that the App Service Plan it belonged to was running out of available sockets, and I moved the app to its own App Service Plan that no other app belongs to. But after a couple of days the exception started occuring again. Since it's running on a consumption plan there's no way that I'm aware of to control the number of available sockets.

The function runs thousands of times per day but I only get this error perhaps once or twice per day. It has also been running fine for a couple of years until now. So I'm rather sure it's not some obvious misconfiguration.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
2,992 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Takahito Iwasa 4,641 Reputation points MVP

    Hi, @hnnsj

    Perhaps you will have problems when you have reached the outbound limit.
    In the case of App Service Plan, there is an upper limit for each plan.

    As a fundamental measure, in the case of App Service Plan, it is necessary to scale up and consider a mechanism for reusing communication on the application side.

    0 comments No comments

  2. MughundhanRaveendran-MSFT 12,221 Reputation points

    @hnnsj ,

    Thanks for reaching out to Q&A.

    Given the frequency of the issue, it appears to be transient issue which is common in cloud computing world. Having a retry mechanism should take care of transient issues.

    However, if the issue is seen consistently/in a certain pattern, you will have to look into the outbound connections of the function app. The number of available connections in a Consumption plan is limited partly because a function app in this plan runs in a sandbox environment. One of the restrictions that the sandbox imposes on your code is a limit on the number of outbound connections, which is currently 600 active (1,200 total) connections per instance. When you reach this limit, the functions runtime writes the following message to the logs: Host thresholds exceeded: Connections. For more information, see the Functions service limits.

    Please look into this article to manage connections in function app :

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.