-
Notifications
You must be signed in to change notification settings - Fork 195
Open
Description
My socket disconnected when my page rerendered.Here is my frontend code:
// create a socket connection
PinusSocketioClient(ip, port, onConnect: (client) async {
final accessToken = await HttpHandler.getAccessToken();
// emit a message to get result
client.request([
apiMap.CONNECTOR_entry,
{
'roomId': roomId,
'userId': userId,
'userName': userName,
'userAvatar': userAvatar,
'lat': 0.1,
'lon': 0.1,
'accessToken': accessToken
},
(data) {
// getAllUserInfo
_getAllUsers().then((usrs) {
// a rerender events, when comment canceled,the rerender function disconnected my connection
// updateUsers(usrs);
completer.complete(true);
});
}
]);
}, onDisconnect: (client) {
// when rerendered, here comes.
print('disconnected ${DateTime.now()}');
connected = false;
_currClient = null;
client.disconnect();
if (!completer.isCompleted) {
completer.complete(false);
}
}, onError: (err, client) {
print('error');
connected = false;
client.disconnect();
if (completer.isCompleted) {
completer.complete(false);
}
});
When the rerender function has been called, my node socketio process consoled 'ping timeout' immediatly.I know about socketio's ping/pong theory, but it happens every time when I rerendered and it is not caused by io's heartbeat.
Then my frontend application closed because of 'transport close'.
I am very certain that my socket does not disposed by myself. Socket is singleton in my app and cannot be garbage collection.
I'm very curious about the bug in my app and I can't find a way to solve it 😭😭😭. I'll be truly and deeply grateful for an answer!
Metadata
Metadata
Assignees
Labels
No labels