leporo / tornado-redis

Asynchronous Redis client that works within Tornado IO loop.
666 stars 162 forks source link

messages are not sent if page is reloaded. #51

Closed imnishantk closed 10 years ago

imnishantk commented 10 years ago

Running the demos/sockjs/app.py, works fine when the chat window is loaded first but if the page is reloaded, the chat page fails to send msg.

The logs states that, the class SockJSSubscriber(BaseSubscriber) didn't get an unsubscribe message for the broadcast_channel but for the private channel.

logs: Class SockJSSubscriber(BaseSubscriber) on_message:

First time when started:

Message(kind=u'subscribe', channel=u'broadcast_channel', body=1, pattern=u'broadcast_channel') Message(kind=u'subscribe', channel=u'private.10ba6', body=2, pattern=u'private.10ba6')

After refresh:

Message(kind=u'unsubscribe', channel=u'private.10ba6', body=1, pattern=u'private.10ba6') Message(kind=u'unsubscribe', channel=u'broadcast_channel', body=0, pattern=u'broadcast_channel')

and when one more tab is opened: Message(kind=u'subscribe', channel=u'broadcast_channel', body=1, pattern=u'broadcast_channel')

Message(kind=u'subscribe', channel=u'private.301ee', body=2, pattern=u'private.301ee')

Message(kind=u'subscribe', channel=u'private.4c759', body=3, pattern=u'private.4c759')


So after opening the second tab, chat works fine, but it should also work in single tab .

leporo commented 10 years ago

Thank you. I pushed a fix, please check - does it work for you?

imnishantk commented 10 years ago

Thanks for the reply. It's not working. After two reload, the page fails to unsubscribe (venv)nk@vjay ~/chat2/tornado-redis/demos/sockjs $ redis-cli monitor OK 1385411582.353728 [0 127.0.0.1:46640] "SUBSCRIBE" "broadcast_channel" 1385411582.354629 [0 127.0.0.1:46640] "SUBSCRIBE" "private.25048" 1385411588.043292 [0 127.0.0.1:46640] "UNSUBSCRIBE" "private.25048" 1385411588.043622 [0 127.0.0.1:46640] "UNSUBSCRIBE" "broadcast_channel" 1385411588.163986 [0 127.0.0.1:46640] "SUBSCRIBE" "broadcast_channel" 1385411588.164854 [0 127.0.0.1:46640] "SUBSCRIBE" "private.098a2" 1385411594.227531 [0 127.0.0.1:46640] "UNSUBSCRIBE" "private.098a2"

imnishantk commented 10 years ago

It works fine if I reverse the unsubscription order in /demos/sockjs/app.py.

def on_close(self): subscriber.unsubscribe('broadcast_channel', self) subscriber.unsubscribe('private.{}'.format(self.user_id), self)

Send the 'user leaves the chat' notification

    self._enter_leave_notification('leaves')
leporo commented 10 years ago

Thank you for your help. The issue doesn't reproduce on my local system any more, the recent fix seem to solve it for me, so I need more help from you:

To run the test suite please run these commands in the root folder of tornado-redis Git repository clone:

pip install tox
tox

Please make sure you're using a new virtual environment for this, so it won't affect your other works.

You'll also need a running redis-server instance to complete the tests.

If you don't want to install Python 2.6 and PyPy to run all tests, you may specify the interpreters you're interested in like this: tox -e py27,py33 and run the test suite for them.

Here is the MONITOR command output on my system when I start the demo and reload the page:

1385455635.710726 [0 127.0.0.1:56691] "SUBSCRIBE" "broadcast_channel"
1385455635.711392 [0 127.0.0.1:56691] "SUBSCRIBE" "private.1550a"
1385455638.238848 [0 127.0.0.1:56691] "UNSUBSCRIBE" "private.1550a"
1385455638.239042 [0 127.0.0.1:56691] "UNSUBSCRIBE" "broadcast_channel"
1385455638.388083 [0 127.0.0.1:56691] "SUBSCRIBE" "broadcast_channel"
1385455638.388816 [0 127.0.0.1:56691] "SUBSCRIBE" "private.a0f81"
1385455638.954792 [0 127.0.0.1:56691] "UNSUBSCRIBE" "private.a0f81"
1385455638.955082 [0 127.0.0.1:56691] "UNSUBSCRIBE" "broadcast_channel"
1385455639.088436 [0 127.0.0.1:56691] "SUBSCRIBE" "broadcast_channel"
1385455639.089047 [0 127.0.0.1:56691] "SUBSCRIBE" "private.b1fcd"
imnishantk commented 10 years ago

tox results: OK [I 131126 15:16:15 testing:609] PASS ___ summary ____ ERROR: py26: InterpreterNotFound: python2.6 py27: commands succeeded ERROR: pypy: InterpreterNotFound: pypy py33: commands succeeded


I am using python 2.7.4 . (26nov_b)nk@vjay ~/26nov_b/tornado-redis $ pip freeze argparse==1.2.1 distribute==0.6.34 py==1.4.18 redis==2.8.0 sockjs-tornado==1.0.0 tornado==3.1.1 tornado-redis==2.4.12 tox==1.6.1 virtualenv==1.10.1 wsgiref==0.1.2 (26nov_b)nk@vjay ~/26nov_b/tornado-redis $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26)

leporo commented 10 years ago

Thanks a lot.

I tried to mimic your configuration and had the same result as listed above, the issue seem to be solved on my system.

May I ask you to update your tornado-redis package: pip install -U tornado-redis before trying the demo one more time? Does the issue persist?

You may also try running the sockjs demo from the tornado-redis source root using the following command: PYTHONPATH=. python demos/sockjs/app.py.

imnishantk commented 10 years ago

Hey thanks, Even I was giving a shot in another machine. Its working fine there, the tornado-redis for that machine was 2.4.13 . So I updated mine and it is working fine now.