yowsup icon indicating copy to clipboard operation
yowsup copied to clipboard

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

Open casperklein opened this issue 13 years ago • 38 comments

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?

casperklein avatar Jan 12 '13 01:01 casperklein

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.

dswd avatar Jan 12 '13 10:01 dswd

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

casperklein avatar Jan 12 '13 21:01 casperklein

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

styl3R avatar Jan 13 '13 18:01 styl3R

fixxed or what?

styl3R avatar Jan 14 '13 18:01 styl3R

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

alejandro-amo avatar Jan 15 '13 16:01 alejandro-amo

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="[email protected]" 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="[email protected]" 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="[email protected]" 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="[email protected]" 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="[email protected]" 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="[email protected]" 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

casperklein avatar Jan 15 '13 17:01 casperklein

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.

alejandro-amo avatar Jan 15 '13 17:01 alejandro-amo

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

casperklein avatar Jan 15 '13 17:01 casperklein

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))

alejandro-amo avatar Jan 15 '13 17:01 alejandro-amo

ITS NOT GROUP MESSAGES ONLY PRIVAT MESSAGES man man

styl3R avatar Jan 15 '13 18:01 styl3R

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.

alejandro-amo avatar Jan 15 '13 18:01 alejandro-amo

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 avatar Jan 15 '13 18:01 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?

casperklein avatar Jan 15 '13 18:01 casperklein

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 [email protected] [15-01-2013 18:28]:Loooool [email protected] [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

alejandro-amo avatar Jan 15 '13 18:01 alejandro-amo

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.

casperklein avatar Jan 15 '13 18:01 casperklein

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

alejandro-amo avatar Jan 15 '13 18:01 alejandro-amo

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.

alejandro-amo avatar Jan 15 '13 19:01 alejandro-amo

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="[email protected]" 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!

brainstorm avatar Jan 29 '13 11:01 brainstorm

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.

dswd avatar Jan 29 '13 13:01 dswd

@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.

casperklein avatar Jan 29 '13 17:01 casperklein