Hi, this is not an issue with your code; it’s actually a platform bug that was introduced at the end of April. Specifically, it affects Windows Functions running in Consumption or Y1 plans on 32-bit. What happens is that the process responsible for exposing the Managed Identity endpoint (the sidecar that listens on 127.0.0.1) sometimes starts too late, or doesn’t start at all.
When this process fails, the IDENTITY_ENDPOINT
environment variable ends up missing. At that point, the SDK (ManagedIdentityCredential) tries to fall back to IMDS by calling <removed address>, but since this IP is blocked on Windows App Service, you get the typical "socket in a way forbidden..." exception.
This is a known issue, already being tracked on GitHub in issues #10189 and #10238 for the Functions runtime.
If you want to confirm whether you're hitting this exact problem, you can open Kudu (Console) while the error is happening and simply run echo %IDENTITY_ENDPOINT%
. If it returns empty, you’re indeed facing this specific bug.
The easiest way to get around it is to switch your app to run in 64-bit mode — in that configuration, the sidecar always starts correctly. Alternatively, moving the app to a Linux Consumption or Premium plan also avoids the issue, since Linux directly uses IMDS and doesn’t rely on this sidecar process. There’s also a patch rolling out: if you update your FUNCTIONS_EXTENSION_VERSION to ~4.1045 or newer, that should fix the problem as well. In the meantime, adding some retry logic can help mitigate the symptoms, even if it doesn’t solve the root cause.
As general advice, it’s a good idea to reuse a single instance of DigitalTwinsClient or HttpClient per process, to avoid exhausting available ports, and make sure Always On is enabled if you're using Dedicated or Premium plans. Lastly, I’d recommend keeping an eye on Azure Service Health and the GitHub thread to follow the official progress on the fix.
Once you switch to 64-bit (or to Linux), token requests should go back to 100% success and the exception will disappear.
Let me know if you need help applying the workaround.