-
Notifications
You must be signed in to change notification settings - Fork 136
Description
Hi, I'm using Kuzzle SDK JS for a React Native mobile application and ESP32 devices (using WebSocket custom calls in C/C++ for them).
Both are using API Keys for authentication. So for C++, I'm just setting the jwt key in the pushed JSON.
I'm observing the same behavior on both devices. Or at least something very close.
Context (Environment)
- Kuzzle version: 2.27.4
- Node.js version: 16.20.2
- SDK version: 7.10.7
- Authenticated through: API KEY (k-apikey)
Observations
Everything works well for some time. Then at some point, I'm losing real-time subscriptions.
- On JS SDK side it looks like a disconnect event is triggered.
- On ESP32 no disconnect event is emitted from the socket client (https://github.com/Links2004/arduinoWebSockets)
- When losing a subscription the device is still connected as I can publish new events from it. It has just not received new events from the subscription as it looks not subscribed anymore.
Possible cause
I've seen using an observer on the server side that strange things occur
1. Subscribe on the Server side to presence (click to unfold code)
kuzzle.realtime.subscribe(
index,
"presence",
{},
(notification) => {
if (notification.type !== "user" || !notification.volatile.device) return;
console.log(
`Presence change for device ${notification.volatile.device} to ${notification.user}`,
);
},
{ users: UserOption.all, scope: ScopeOption.none },
);
}- Boot the device and subscribe.
- Disconnect abruptly (like killing the app, or pressing the restart button on an ESP32)
- and therefore boot and subscribe again.
-> Everything works.
Until the server receives the timeout event of the first socket being closed abruptly.
Presence change for device ESP_1 to in
Presence change for device ESP_1 to in
Presence change for device ESP_1 to out
Presence change for device ESP_1 to out
-> It seems it clears all new subscriptions. ?
Possible cause
If confirmed, I'm pretty sure the issue is about hotelClerk thinking it's the same connection and, therefore, the same subscription and clear all ? But it seems the ws instance is generating a uuid v4 for connectionID, so I don't know how its possible.
Might it be related to API Keys usage ?
Issue happens on SDK JS too, so I'm not sure this is related to my implementation
Workaround
- Regularly sending a subscribe request with the same payload as the subscription ID is idempotent ?
- Rely on polling at regular intervals ?