Connection to signalR from Azure function fails with 403 (Forbidden) several times a day for 5 minutes, and then works again

Dorus Peelen 31 Reputation points
2025-02-13T10:47:50.98+00:00

As titel, several times a day our connection to singalR from the azure function fails with a 403 forbidden error. After 5 minutes the connection recovers.

Full Exception :
 Exception while executing function
 /Functions.OrderToSignalR ---> Microsoft.Azure.SignalR.Common.AzureSignalRRuntimeException 
 /Azure SignalR service runtime error. Request Uri
 /https://[***].service.signalr.net/api/hubs/orders/:send?api-version=2022-06-01 ---> System.Net.Http.HttpRequestException 
 /Response status code does not indicate success
 /403 (Forbidden)
   End of inner exception

These calls typical start with a Invoke DefaultAzureCredential.GetToken, ManagedIdentityCredential.GetToken and then a post to [**].service.signalr.net

POST /api/hubs/orders/:send that fails with a 403. These calls repeat 6 times because of the servicebus retry.

Outside the 5 minute window where the calls fails, everything works normal.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,414 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
156 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Khadeer Ali 3,430 Reputation points Microsoft Vendor
    2025-02-13T13:04:41.66+00:00

    @Dorus Peelen ,

    Thanks for reaching out. If you're running into a 403 Forbidden error when connecting to SignalR from your Azure Function, a few things might be causing it:

    • SAS Token Issues: If you're using a SAS token, make sure it's not expired when the client tries to use it. Avoid setting a start time for immediate use, and give it a reasonable expiry time.
    • Authorization Problems: Your function might not have the right permissions to access SignalR. Check if the managed identity or credentials have the necessary access.
    • Too Many Requests: If the service is under heavy load, it might temporarily block new connections. Keep an eye on usage and add some retry logic with a delay.
    • Network Glitches: Sometimes, temporary network issues can cause connection failures. Make sure your function is set up to handle them.
    • CORS Settings: If your function is running from a different origin, double-check that CORS settings allow requests from it.

    Since the connection starts working again after about five minutes, it could be a temporary issue or some rate limiting in action. Adding retry logic in your function should help deal with these hiccups.

    References:

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for "Was this answer helpful." And if you have any further questions, let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.