Missing pubsub messages between client disconnect and reconnect

Nayan Das 71 Reputation points
2021-07-20T06:48:48.707+00:00

We are using Azure web pubsub to push events realtime to devices. The client connects to the websocket url and the server pushes event messages to clients through pubsub using azure pubsub python sdk. We found that the pubsub resends unsent event messages to clients and sometimes it does not.

There are two scenarios:

  • When the device stays unlocked.

When the client app disconnects and reconnects after sometime, the pubsub resends the missing event messages from server during this time. The unsent event messages are even resent to client app when it goes to background and comes to
foreground(reconnects to pubsub) after 1 hour!

  • When the device is locked and unlocked in between

The problem occurs when the device is locked. When its locked we found that the websocket connection gets immediately
disconnected and when the screen is unlocked, the client app does not get the unsent event messages during this period.
The client app, though, keeps on getting the new messages after the device is unlocked.

We want to understand the working of pubsub's retry mechanism in case of unsent event messages and its guarantees. We could not find any documentation related to this in the Microsoft Learn.

Azure Web PubSub
Azure Web PubSub
An Azure service that provides real-time messaging for web applications using WebSockets and the publish-subscribe pattern.
59 questions
{count} vote

Accepted answer
  1. Liangying Wei 756 Reputation points Microsoft Employee
    2021-07-21T01:39:20.577+00:00
    1. Web PubSub itself does not have a message delivery guarantee, it acts as a broker that delivers real-time messages to connected WebSocket clients. So if the WebSocket connection is disconnected, the client does not get the messages sent during this period. if you want to guarantee message delivery, consider supporting it in your application protocol or using a protocol having such mechanism, e.g. MQTT.
    2. "When the client app disconnects and reconnects after sometime, the pubsub resends the missing event messages from server during this time." => No, Web PubSub does not have a mechanism to "resend" messages, it does not preserve messages. Could you describe more about how your server-side sends event messages, is there any retry logic from your server-side?
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Liangying Wei 756 Reputation points Microsoft Employee
    2021-07-21T01:41:31.31+00:00

    Created an issue here https://github.com/Azure/azure-webpubsub/issues/198 to track the status

    0 comments No comments

  2. Nayan Das 71 Reputation points
    2021-07-22T10:34:49.54+00:00

    We kept our client app in background app for 1 hour and could find that the event sent in between are reflected immediately as if it was already there. During this time we could see that the disconnect webhook is called in our app server logs. That's why we came to conclusion that pubsub might be retrying pubsub messages.

    Our server is using python azure messaging sdk to send pubsub messages only once to a pubsub group. There is no retrying logic in our app server.

    0 comments No comments

  3. Liangying Wei 756 Reputation points Microsoft Employee
    2021-07-23T07:22:04.14+00:00

    Web PubSub only delivers real-time messages to connected WebSocket clients. Maybe detailed logs can help us understand the issue better:

    1. Client log when WebSocket connection is connected, disconnected, and when the message is received, with timestamps and the client connection ID in the log.
    2. Server log when it receives client connected/disconnect, and when it sends out the message, with timestamps and the client connection ID in the log
    0 comments No comments