Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

yowsup-cli -l -a -k disconnect after 3 minutes. #54

Closed
casperklein opened this Issue · 38 comments

10 participants

@casperklein

When running "yowsup-cli -l -a -k" I receive after 3 minutes the message "Disconnected because closed".

This only happens, when the used account has received a chat message in the near past.

If enough time is passed since the last chat message, yowsup keeps connected.

Has anyone else seen this issue or an advice how to work around this?

@dswd

Yes I observed this too. I thought it is because the client only sends acknowledgements for normal messages and not group messages and possibly other events that need acknowledgements.

@casperklein

I just noticed, this also happens when sending a message and not only when receiving a message in the near past.

@styl3R

When i start yowsup with the -l -a -k command than i close the connection within 3 minutes :( fixxed?

@styl3R

fixxed or what?

@WhiteHatAlister

and where's the debug output that demonstrates that there is suposedly a bug to fix ?

@casperklein

Good point alist3r. I just forgot to post it :( Hope this helps to find the issue:

YowsupConnectionManager:    >>>>>>>>                         AUTH CALLED
BinTreeNodeReader:  Reader init
Connecting to c.whatsapp.net
WAuth:  Yowsup WAUTH-1 INIT
WAuth:  Starting stream
WAuth:  Sending Features
BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <stream:features>
<receipt_acks>
</receipt_acks>
<w:profile:picture type="all">
</w:profile:picture>
<w:profile:picture type="group">
</w:profile:picture>
<notification type="participant">
</notification>
<status>
</status>
</stream:features>
WAuth:  Sending Auth
BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" user="49176xxxxx" mechanism="WAUTH-1">
</auth>
WAuth:  Read stream start
WAuth:  Read features and challenge
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<stream:features>
<receipt_acks>
</receipt_acks>
<w:profile:picture type="all">
</w:profile:picture>
<notification type="participant">
</notification>
</stream:features>
WAuth:  GOT FEATURES !!!!
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
</challenge>
WAuth:  GOT CHALLENGE !!!!
WAuth:  Sending Response
BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
</response>
WAuth:  Read success
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<success status="active" kind="free" xmlns="urn:ietf:params:xml:ns:xmpp-sasl" creation="1358023144" expiration="1389559144">
</success>
WAuth:  Login Status: success
WAuth:  Expires: 1389559144
WAuth:  Account type: free
WAuth:  Account status: active
Authed 49176xxxxx
YowsupConnectionManager:    starting reader
ReaderThread:   Read thread startedX
ReaderThread:   Waiting, time to die: T-240 seconds
YowsupConnectionManager:    started
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<presence status="dirty" xmlns="w" from="s.whatsapp.net">
</presence>
ReaderThread:   WILL SEND DIRTY
ReaderThread:   SENT DIRTY
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" retry="1" from="49151xxxxx@s.whatsapp.net" id="1358265944-1" t="1358265974">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" from="49160xxxxx@s.whatsapp.net" id="1358265942-1" t="1358265979">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" from="49177xxxxx@s.whatsapp.net" id="1358266089-1" t="1358266090">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" from="49177xxxxx@s.whatsapp.net" id="1358266113-2" t="1358266114">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" from="49177xxxxx@s.whatsapp.net" id="1358266276-3" t="1358266277">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<message type="chat" from="49177xxxxx@s.whatsapp.net" id="1358266298-4" t="1358266300">
<received xmlns="urn:xmpp:receipts">
</received>
</message>
ReaderThread:   Waiting, time to die: T-240 seconds
BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<ib from="s.whatsapp.net">
<offline count="6">
</offline>
</ib>
ReaderThread:   Waiting, time to die: T-240 seconds
ReaderThread:   Waiting, time to die: T-210 seconds
ReaderThread:   Waiting, time to die: T-180 seconds
ReaderThread:   Waiting, time to die: T-150 seconds
ReaderThread:   Waiting, time to die: T-120 seconds
ReaderThread:   Waiting, time to die: T-90 seconds
ReaderThread:   Waiting, time to die: T-60 seconds
ReaderThread:   Socket closed, got 0 bytes!
ReaderThread:   Sending disconnect
@WhiteHatAlister

I just tested a bit trying to reproduce similar circumstances (adding a group, group msgs, group image change notifications, and the like).

and yes, sometimes I can reproduce it. self.ping does not appear.

ReaderThread: Waiting, time to die: T-240 seconds
ReaderThread: Waiting, time to die: T-210 seconds
ReaderThread: Waiting, time to die: T-180 seconds
ReaderThread: Waiting, time to die: T-150 seconds
ReaderThread: Waiting, time to die: T-120 seconds
ReaderThread: Waiting, time to die: T-90 seconds
ReaderThread: Socket closed, got 0 bytes!
ReaderThread: Sending disconnected because of closed
YowsupConnectionManager: Setting state to 0
Disconnected because closed

I'm not sure that's a problem of yowsup. I don't think so

anyway, I'm still learning and grasping yowsup's code, so I am not the best person to make any assertion. Just guessing.

@casperklein

Thank you for your investigation. fyi: I only send/receive "normal" user-to-user messages. No group stuff or other things.

Edit: Could this be the cause of the issue:

<presence status="dirty" xmlns="w" from="s.whatsapp.net">
</presence>
ReaderThread:   WILL SEND DIRTY
ReaderThread:   SENT DIRTY
@WhiteHatAlister

yes, yowsup-cli has not all the methods and signals implemented so you wont.

but that's easy to solve:

        mySignalsInterface.registerListener("group_messageReceived", onGroup_messageReceived)

and then (just an example)...

def onGroup_messageReceived(messageId,jid,author,content,timestamp,receiptRequested, pushname):
    formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M')
    print "[%s] (%s) %s:%s"%(formattedDate, jid, pushname, content)
    if receiptRequested:
            myMethodsInterface.call("message_ack",(jid,messageId))
@styl3R

ITS NOT GROUP MESSAGES ONLY PRIVAT MESSAGES man man

@WhiteHatAlister

we are missing the point.
casperklein has already understood the fact that group msgs are not implemented, but anyway, it seems something is wrong with pingpongs when you receive a group msg. which is not suppossed to happen.

@casperklein

Thanks, saved for later use eventually ;-) ATM I don't need group stuff.

BTW: I worked around the disconnect issue in BASH with this:

while [ true ]; do yowsup .......; done

But a proper solution would be great. If I can assist you with further support, let me know.

@styl3R: Calm down ;-) We should be happy that alist3r and others are trying to help. Such answers I suppose don't encourage someone to help further. Think about it.

@casperklein

Did I overlook something? My log does not include any reference to group stuff? So this can not be an group stuff specific issue, right?

@WhiteHatAlister

sorry, I just "skimmed" your log, and then tested several things at the same time.
I have tested more roughly, and it's a message specific issue.
my fault. sorry.

me@myhost:~/src/yowsup/src$ ./yowsup-cli -l -k -a
Connecting to c.whatsapp.net
Authed 346688813xx
347222788xx@s.whatsapp.net [15-01-2013 18:28]:Loooool
347222788xx@s.whatsapp.net [15-01-2013 18:28]:Lmao
Disconnected because closed

the two messages were sent before I connect, so they and were holding on in the server.

I'm pretty sure we are missing something. Looking backwards issue list gives me no clue. I hope we are not annoying yowsup's issue list with dumb things, Tarek has a lot of patience with us :P

@casperklein

This does not happen only when starting yowsup and there are missed messages.

I've also had yowsup running for hours, receive then a message (the sender receives an ack), and after 3min => disconnect.

@WhiteHatAlister
if ready[0]:
            try:
                node = self.socket.reader.nextTree()
            except ConnectionClosedException:
                #print traceback.format_exc()
                self._d("Socket closed, got 0 bytes!")
                #self.signalInterface.send("disconnected", ("closed",))
                self.sendDisconnected("closed")
                return

this is the trace:

Traceback (most recent call last):
File "/home/alex/src/yowsup/src/Yowsup/connectionmanager.py", line 755, in run
node = self.socket.reader.nextTree()
File "/home/alex/src/yowsup/src/Yowsup/ConnectionIO/bintreenode.py", line 175, in nextTree
self.readStanza();
File "/home/alex/src/yowsup/src/Yowsup/ConnectionIO/bintreenode.py", line 48, in readStanza
num = self.readInt8(self.rawIn)
File "/home/alex/src/yowsup/src/Yowsup/ConnectionIO/bintreenode.py", line 76, in readInt8
return i.read();
File "/home/alex/src/yowsup/src/Yowsup/ConnectionIO/connectionengine.py", line 104, in read
raise ConnectionClosedException("Got 0 bytes, connection closed");
ConnectionClosedException: Got 0 bytes, connection closed

@WhiteHatAlister

not sure why the connection engine raises a ConneectionClosedException everytime we try to read from the socket and we get 0 data.
Is this a test to know if the socket has been closed on the other side?
Dunno, I think it's better to stop guessing and messng, and wait patiently to other people which is more familiarized w/ the code and the protocol.

@brainstorm

Talking about private messages only...

My connections die before the timeout (time to die) too.

$ ./yowsup-cli -c config.aus -k -a -i <telf_user>
(...)
ReaderThread:   Waiting, time to die: T-90 seconds
ReaderThread:   Waiting, time to die: T-60 seconds
will go soon to sleep
BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <message to="bar@s.whatsapp.net" type="chat" id="foo-2">
<x xmlns="jabber:x:event">
<server>
</server>
</x>
<body>sent after T-60</body>
</message>

ReaderThread:   Socket closed, got 0 bytes!
ReaderThread:   Sending disconnected because of closed
YowsupConnectionManager:    Setting state to 0
Disconnected because closed

Other than that, works like a charm, thanks @tgalal!

@dswd

I just implemented handlers for all notifications that at least print them. I observed that everytime I had this problem I got some old notifications right after login and the connection would die after a few minutes. After some time the server seems to drop the notifications even if they are not acknowledged but in the meantime the connection keeps closing. When I implemented the notifications, the problem suddenly disappeared and now I have a stable connection since a few days with only few reconnects due to DSL disconnect.

I think the library should handle the notification acknowledgements on its own as this seems be critical for connection stability.

@casperklein

@dswd That sounds great. Unfortunately I don't know python very much. Could you please post the code snippet with the handlers for all notifications that just prints them out as you mentioned? That way I could easily "paste" them to ListenerClient.py. Thank you in advance.

@brainstorm

@dswd Indeed, please post your modifications, or better, pull request to the yowsup repository directly...

@dswd

My code is contained in the pull request #46

@casperklein

@dswd I just tested your main-cli.py from your repo. That did not fix my problem. Got still disconnects:

@???:> [30-01-2013 20:46] Logged in as xxxxx
[30-01-2013 20:46] xxxxx is now available
[30-01-2013 20:49] Disconnected because closed
Connecting to c.whatsapp.net
[30-01-2013 20:49] Logged in as xxxxx
[30-01-2013 20:49] xxxxx is now available

Anyway, thank you for your help.

@dswd

@casperklein Sorry, it works for me

@ghost

Maybe you have some ports blocked, check your firewall and router configuration. As far as I know Whatsapp/XMPP uses 5220

@shirioko

What is your socket timeout setting? WhatsApp sends a ping every 3 minutes, so your timeout should be more than 180000ms

@casperklein

@TheKirk Nothing is blocked. All outgoing traffic is permitted.

@shirioko I haven't changed that. So I think the default python timeout settings apply. I am running yowsup on debian 6.0.6 with python 2.6.

And rememeber, that only happens, if the account received a message in the near past. If that is not the case, I can run yowsup 1day or more without disconnect.

@dswd

@casperklein: Could you start the yowsup-cli in debug mode and check if certain messages are received each time directly after login?
If so, there might be another message type not included in the library that requires acks.

@techmaniack

Using yowsup for a while (only for private messages now) and facing the same issue of disconnect after 3 minutes.

Otherwise it works like a charm. Thanks @tgalal \m/

@aguiraf

got it !!
the timeout set for autoPong() in Yowsup is 240 sec while on whatsapp side they lowered the timeout for automatic disconnection to 180 sec!
so I changed in Yowsup/connectionmanager.py:
#self.timeout = 240 (line 685)
self.timeout = 180
and...
#if self.timeout-countdown == 210 and self.ping and self.autoPong: (line 738)
if self.timeout-countdown == 150 and self.ping and self.autoPong:

so the ping() method fires just in time before disconnection

Now it's up to best coders then me to patch the code with more elegant solution...

@WhiteHatAlister

nice one, aguiraf. thanks!

@brainstorm

@aguiraf... just curious, where did you get that new timeout? It would be helpful to know if there's another similar change from WhatsApp in the server side in the future...

@aguiraf

@brainstorm: well, I just noticed, as many others did, that yowsup get disconnected exactly after 3 minutes of inactivity; then I saw, in debug mode, that tgalal (thank you a lot for your great work) hardcoded a timeout /countdown of 4 minutes (240 s) for sending the ping/keepalive message to the wa server;
I think the guys from wa have lowered the timeout... It would be useful have the timeout value in the configuration file or command line parameter, just in case they change it again...

@casperklein

Thanks aguiraf! That solved the issue for me too. But just for clarification: I think the wa guys did not globally lowered the timeout. Only in specific circumstances (e.g. when send/receieved a message in the near past). Otherwise yowsup works fine and keeps connected (for me at least) with the original hardcoded timeout.

@brainstorm

Thanks @aguiraf, tested and working :+1:

Pull request #96 fixes this issue.

@casperklein casperklein closed this
@awesomebytes

Hello, I noticed that I got disconnections also. I lowered the time to 150s ( https://github.com/tgalal/yowsup/blob/master/src/Yowsup/connectionmanager.py#L710 ).

And the next timeout check to 120s ( https://github.com/tgalal/yowsup/blob/master/src/Yowsup/connectionmanager.py#L761 ).

I'm just playing around, but I keep the thing on for quite some minutes. I was getting disconnections everytime, and for now it's not disconnecting.

@xhijack

Still doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.