Nerixyz / instagram_mqtt

Realtime and Push Notification (FBNS) support for the instagram-private-api
MIT License
252 stars 50 forks source link

Mqtt client tries to connect nonstop #28

Closed Ektaros closed 4 years ago

Ektaros commented 4 years ago

Occasionally there is a problem with realtime subscription - it starts spamming EPIPE errors consuming the processor time. Safe disconnect does not work. It happens with fbns too, but extremely rarely the ratio is like 1 to 25.

Is there any way i can just stop listening to incoming packets then this happens? And is it okay to just create a new connection over the old one?

I do not think i can provide the logs on the situation tho. The problem is random so i cant just separate one account like i did last time and the logs from many accounts comsume too much resources.

Ektaros commented 4 years ago

Randomly got logs for this event. About how I handler realtime errors: Only if i get "Mqtt client got disconnected" error i call realtime.disconnect() and after several mins create new RealtimeClient confugure and call connect(). Also if i get more than 7 EPIPE errors within a minute I terminate the process. This happend here. Here are the logs: https://pastebin.com/S7djKDTc I have 5 accounts running and collecting logs at the same time. Tried my best to filter the ones related to the problematic account but if something does not match up have full version on me.

Ektaros commented 4 years ago

@Nerixyz Any thoughts on this?

Nerixyz commented 4 years ago
2020-03-20T09:07:24.470Z mqtt:client:packet Sent MQTToTConnectRequestPacket
2020-03-20T09:07:24.474Z ig:mqtt:mqttot edge-mqtt.facebook.com:443: Disconnected.

These are probably the most important lines. You try to connect while the client is still connected, so it disconnects.

Ektaros commented 4 years ago

Could not find any logic that could lead to calling connect when the client is already connected. I call connect only at the start of the code and via a 1 function that calls disconnect and after several seconds calls connect. Ofc i might have missed smth or written a bad code. Anyways solved the problem by modifying MqttClient's functions: Now setDisconnectedcalls() calls clearTimeout(this.connectTimer) before calling the original function and disconnect() calls clearTimeout(this.connectTimer) after the original function.