Socket Exception while generating Azure AAD Auth token

Abhijit Jadhav (INFOSYS LIMITED) 11 Reputation points Microsoft Vendor
2023-10-23T17:52:19.9566667+00:00

We have service bus trigger function app and in this function we make call to one of the web api endpoint from this function. Before making api call we generate auth token using client id and secret and this auth token is used to authenticate web api endpoint.

We are getting socket exception while generating Azure AAD auth token using client id and secret. We are using MSAL library function to generate auth token. This client id is used by function app since last 2 years, we started seeing this issue since 2 months.

Initially we thought, it could be infra issue so we have upgraded app service plan of the function app to Premium v2 P1V2, but still the issue persist and overall occurrence is very frequent.

PFB details of exception.

Exception type - System.Net.Sockets.SocketException

Stack trace-

-An error occurred while sending the request. -

-Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

-An existing connection was forcibly closed by the remote host

An error occurred while sending the request.","type":"System.Net.Http.HttpRequestException","id":"21828179","parsedStack":[{"assembly":"System.Net.Http, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","method":"System.Net.Http.HttpConnection+<SendAsyncCore>d__64.MoveNext","level":0,"line":0},{"assembly":"System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":1,"line":0},{"assembly":"System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":2,"line":0},{"assembly":"System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":3,"line":0},{"assembly":"System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,386 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,241 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,317 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,131 questions
{count} votes