0xzer / messagix

A Go library to interact with the Instagram/Facebook API
MIT License
10 stars 2 forks source link

FB closing connection after around minute despite ping-pong. #3

Open JabLuszko opened 1 month ago

JabLuszko commented 1 month ago

Quick log. The handshake data seems to be correct comparing to my browser. This is (re-)using cookies from webbrowser, but I made sure that it was closed for like 60 minutes if FB couldn't handle sessions or something.

Any idea what is happening? I've fiddled with intervals (up to 8 seconds) and socket timeouts - FB still closes connection.

Fri Aug  2 02:52:44 2024 INFO Setting configs.needSync to true
Fri Aug  2 02:52:48 2024 INFO Loaded versionId & appId appId=2220391788200892 versionId=7940365299384809
Fri Aug  2 02:52:48 2024 INFO Configs successfully setup! broker=wss://edge-chat.facebook.com/chat?region=odn
Fri Aug  2 02:52:48 2024 DEBUG Dialing socket broker=wss://edge-chat.facebook.com/chat?region=odn&cid=YYYYYYYYYYYYYYY&sid=XXXXXXXXXXXXXXXXXXXXX
Fri Aug  2 02:52:49 2024 INFO Client is ready! connectionCode=CONNECTION_ACCEPTED isNewSession=false
Fri Aug  2 02:52:49 2024 INFO Starting handshakeInterval...
Fri Aug  2 02:52:57 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:52:57 2024 INFO Sent handshake to socket
Fri Aug  2 02:52:57 2024 INFO Got PingResp packet
Fri Aug  2 02:53:05 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:05 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:05 2024 INFO Got PingResp packet
Fri Aug  2 02:53:13 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:13 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:13 2024 INFO Got PingResp packet
Fri Aug  2 02:53:21 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:21 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:21 2024 INFO Got PingResp packet
Fri Aug  2 02:53:29 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:29 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:29 2024 INFO Got PingResp packet
Fri Aug  2 02:53:37 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:37 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:37 2024 INFO Got PingResp packet
Fri Aug  2 02:53:45 2024 DEBUG Sending handshake data to socket hex="c0 00"
Fri Aug  2 02:53:45 2024 INFO Sent handshake to socket
Fri Aug  2 02:53:45 2024 INFO Got PingResp packet
Fri Aug  2 02:53:51 2024 INFO Socket was closed. code=1000 text=Bye
0xzer commented 1 month ago

Not sure, haven't worked on this repo for a while and I don't have any plans on continuing it. Are you using a proxy? If it's consistently disconnecting after 8 seconds it would seem... weird? Maybe it's your connection? How are you using the library? Is your main program loop constantly running?

JabLuszko commented 1 month ago

It's not disconnecting after 8 seconds - it takes around 1 minute from the start. / 8 second was note for me fiddling (decreasing) timer for PINGREQ just to make sure it's not hitting some funny 0.0002 seconds something edge-case/

Main program loop is running - it's not that. Plus it's FB servers closing connection - that 1000 Bye comes from them, isn't it? It's like that PINGREQ is not working... but there are PINGRESP? On the other hand that PINGRESP can be generate by sending anything - I've messed with a structure for testing and it was still giving PINGRESP even for some crazy packets :|

No proxy, no magic - direct connection.

Also if I send some chat messages while this connection last for that 1 minute it does not extend the 1 minute thing - I would assume chat messages should extend the time as connection is active or FB don't care about that and PING is everything? This also would suggest it's not some websocket internal (client side) timeout as those chat messages are getting sent and showing up.

msgBuilder := cli.Threads.NewMessageBuilder(threadId)
(...)
tableResp, err := msgBuilder.Execute()

If this is kinda abandoned do you know any other lib [whatever lang] that works with lightspeed thing for FB chat?

0xzer commented 1 month ago

I never had this issue, but I have heard of it before.

You can check out the updated messagix library (forked from this, not maintained by me) here.

Otherwise you can try to debug the issue by comparing the socket payloads in the library vs web connection, there is most likely something small that is different which you are missing