question

NayanDas-0964 avatar image
2 Votes"
NayanDas-0964 asked NayanDas-0964 commented

User not found returned by Azure web pubsub rest api

We have created the webhooks for /connect and /connected in our server and we get those endpoints called when client connects to pubsub using websocket. We want to add the connected user to be added to certain pubsub groups and we do that in /connected webhook. The problem is sometimes the pubsub rest api throws User not found error when trying to add the user to a group.

If addition of user to the group fails, the server disconnects the current connection and the client reconnects. This is resulting in an endless loop of client reconnection since the pubsub rest api constantly throws "User not found" in /connected webhook.

Solutions we have tried:

  • Add user to group in /connect endpoint instead of /connected. Same error gets thrown.


  • Add connection to group instead of user. We are currently monitoring that and would get back with our observation.


Note: The server is not using pubsub rest api directly. Its using azure messaging python sdk. Rest api here


azure-web-pubsub
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

vicancy avatar image
1 Vote"
vicancy answered vicancy commented

The problem is sometimes the pubsub rest API throws User not found error when trying to add the user to a group.

This sounds like a service bug that the user is not yet completely registered when the connected event is triggered. Are you using Free tier or Standard tier? Does it happen frequently? It would be appreciated if you could provide a min-repro project/steps.

There is one convenient way to add the connection to a group when /connect, to leverage the CloudEvents response groups in the connect response body: https://github.com/Azure/azure-webpubsub/blob/main/docs/references/protocol-cloudevents.md#success-response-format

The property provides a convenient way for users to add this connection to one or multiple groups. In this way, there is no need to have an additional call to add this connection to some group.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NayanDas-0964 avatar image
0 Votes"
NayanDas-0964 answered NayanDas-0964 commented

We have upgraded the plan of pubsub to Standard tier and we are currently monitoring the application. When our pubsub was in free tier, the problem occurred atleast once daily.

Below the post function handles the POST /connected webhook endpoint

 class ConnectedEventHandlerView(APIView):
     def post(self, request):
         user_id = request.headers["Ce-Userid"]
         connection_id = request.headers["Ce-Connectionid"]
    
         try:
             users = User.objects.filter(pk=user_id)
             if users:
                 user = users[0]
    
             pubsub_group_name = create_own_pubsub_group(user)
             response = pubsub_service_client.send_request(
                 build_add_user_to_group_request(
                     settings.AZURE_PUBSUB_HUB_NAME,
                     pubsub_group_name,
                     user_id,
                 )
             )
    
             if response.status_code == 200:
                 return Response()
             else:
                 local_logger.error(
                     f"status code {response.status_code}, response body {response.text}"
                 )
                 logger.error(
                     f"Could not add connection to groups. user_id {user_id}, connection_id f{connection_id}"
                 )
    
                 raise Exception("Could not add connection to groups")
         except:
             response = pubsub_service_client.send_request(
                 build_close_client_connection_request(
                     settings.AZURE_PUBSUB_HUB_NAME, connection_id
                 )
             )
                
             return Response(status=400)


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @NayanDas-0964 How is it going now? Do you still see errors after switching to Standard?

For the Free one that you encountered 404 errors when connected, could you send me lianwei(at)microsoft.com your instance id and the timestamp when the error took place for me to have a further investigation?

0 Votes 0 ·

We are currently testing and will get back to you guys once we have confirmation from our end.

Yes, we shall send you the instance id at your email address.

0 Votes 0 ·