Skip to content

Redis stream, state recovery on multiple offline return same last value (no update offset) #5419

@KrakenTyio

Description

@KrakenTyio

Describe the bug
We migrate from clasic redis to redis stream for state recovery purpose.
Migration was success but during testing we saw issue about reconection.
After succes 1 recovery state, another recovery without any actions always return same previous state.

To Reproduce
When we testing on 2 tabs, do changes on both, and syncing was ok.
Then when 1 is going offline (by devtools) and we do some changes on 2, then go back on 1 and go back online (remove network offline), missing states was recovere (OK).
On 1 tab dont do any changes, go again offline and back online, but somehow again we got same recovery state like before.
After reconnect client send same offset, and looks like recovered state not cointain new offset which should be set as read and new offset for another reconection.

What is help to do any action which create new offset, but its not solution.

Please fill the following code example:

Socket.IO server version: latest on microservice and fe 4.8.1
"@socket.io/redis-streams-adapter": "^0.2.2",

Testing example i dont have, but can provide debug on fe console

this.ioSocket = new Server(
            runningServer,
            Object.assign(
                {
                    cors: {
                        origin: [
                            /localhost:{0,1}\d*$/,
                            .......
                        ],
                        maxAge: 86400,
                        credentials: true,
                    },
                    pingTimeout: 5000,
                    pingInterval: 5000,
                    adapter,
                },
                redisStream
                    ? {
                          // Enable connection state recovery for FE clients
                          connectionStateRecovery: {
                              maxDisconnectionDuration: recoveryMinutes * 60 * 1000,
                              // Skip middlewares on recovery to preserve authentication
                              skipMiddlewares: true,
                          },
                      }
                    : {},
            ),
        );
if (!this.config.options) {
                this.config.options = {
                    query: this.defineQueryOpts(),
                    withCredentials: true,
                    autoConnect: false,
                    rememberUpgrade: true,
                    reconnectionDelay: 200,
                    reconnectionDelayMax: 2000,
                    timeout: 6000,
                };
            }

described issue is on ns /diary

  1. tab get connection and emit change with id 1763652466348-0 after that he goes offline
Image
  1. tab has same action and when 1 tab is offline do action with id 1763652507956-0
Image
  1. tab after back from offline
    as you can see its reconnect with previos offset 1763652466348-0 (its ok)
    receive data with id 1763652507956-0, but id in response missing (probably he cannot create new offset)
Image

Again withou any changes 1. tab goes offline and back online
again it send same offset like before with id 1763652466348-0 (its not ok), probably should be more higher (like ...07956-0)
and again response same recovery state what was before (1763652507956-0), but again offset id is not present in recovery state
Image

Expected behavior
Expected is when state recovery is received, new offset should be send and set for FE imediately, to prevent duplicate recovery in row with multiple disconection

Metadata

Metadata

Assignees

No one assigned

    Labels

    to triageWaiting to be triaged by a member of the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions