Socket Exception while generating Azure AAD Auth token
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