hagsteel / swampdragon

swampdragon
Other
557 stars 73 forks source link

subscribe to redis channel not solid working #119

Open blodone opened 9 years ago

blodone commented 9 years ago

Hi,

The subscribe to a redis channel is not working all the time and the channels in redis have a trailing pipe

one try: 127.0.0.1:6379> PUBSUB 'channels' 1) "contacts|" 2) "sysnotifications|" 3) "msglist|" 4) "feedmessage|"

second try after reloading the page: 127.0.0.1:6379> PUBSUB 'channels' '*' 1) "sysnotifications|" 2) "msglist|"

again page reload: 127.0.0.1:6379> PUBSUB 'channels' '*' (empty list or set)

unfortunately i have 4 channels and printed out debug info on channel subscribe: sub_provider subscribe to ['sysnotifications|'] sub_provider subscribe to ['feedmessage|'] sub_provider subscribe to ['contacts|'] sub_provider subscribe to ['msglist|']

If i try to debug the tornadoredis Client manually for RedisSubProvider i got the following, so i think it tries to subscribe:

In [5]: r._subscriber.subscribers Out[5]: defaultdict(<class 'collections.Counter'>, {'feedmsg|': Counter({None: 1})})

Any calls like r._subscriber.redis.get(valid_key) result with None so i dont know how to debug any further

Also if the channel is subscribed and there is a Message published on that channel its not transferred to the websocket connection.

blodone commented 9 years ago

Now im receiving updates of the redis subscribe to the websocket connection again... its strange, i did not modify my code.

just debugged and I did not see any close messages of a unsubscribe / close... I pointed out that a publish from redis -> websocket was not transferred.

Is there any chance to debug that on the server or add more debug to the browser console?

Update: 12hours later its not working anymore, without touching the code... its subscribing without any close and no message seems to be received from redis to tornado, so nothing is send out through websocket

I tried it with the tornadoredis chat example on the same project at the same channel on redis and the subscribe is working, the messages are being received by tornadoredis but not on swampdragon.

2.Update I tried to debug the SockJSSubscriber connection on unsubscribe and on_message, also put some console.log in the swampdragon.js SockJS on_message... Sometimes the tornadoredis connection is subscribing to redis, sometimes while i see NUMSUB subscribers increase or not.

But the Message won't get to the websocket client running swampdragon, but gets to the same client running native sockjs 0.3 from the tornadoredis chat example

3. Update Now i have the state that one of the channel is registered in redis and is receiving updates. The other channel is not getting subscribed and on_message at the client browser is not getting websocket packets from swampdragon server.

hagsteel commented 9 years ago

The trailing pipe is supposed to be there.

Have you tried running one of the example projects like this one: https://github.com/jonashagstedt/swampdragon/tree/master/chat_example

to see if you have the same issue?

It's impossible to know if the problem is with SD, one of the other components, or your code.

blodone commented 9 years ago

I will try that and point out if there is any mistake in my code.... But it shouldnt be workin... i tested it about one hour in the night it was rock solid... then 12hours later... broken... I use AngularJS and updated Version to 1.3.16, switched from redis 2.8.x to 3.0.2 on debian and i put in many debug messages, I also tried to use sockjs 1.0 in swampdragon.js, it seems to work without problems but doesn't solve my problem... you can see the changes for debug on my branch. The Connections are always subscribed but no disconnect / close messages are received.... I'll test it with your example and give you feedback

UPDATE

I tested the chat example, its working.... but not when the tornado server is in "broken" state.... It seems that subscribing to many channels at once will lead to a broken tornado server which does not respond to a subscribe of the tornadoredis.pubsub.SockJSSubscriber...

I saw a ticket on tornadoredis: https://github.com/leporo/tornado-redis/issues/79 could that be an issue im running on?

Currently my code runs.... then i restarted the swampdragon server.... then my client got this strange error: [Exception... "The connection does not exist" nsresult: "0x804b000c (NS_ERROR_NOT_CONNECTED)" location: "JS frame :: http://x.x.x.x/assets/js/app.js :: browserifyShim/SockJS</WebSocketTransport.prototype.doSend :: line 75004" data: no] after subscribing...

Now if i reload the page i won't get any on_message from SockJSSubscriber anymore...

Yes that seems to be the problem....

If i restart the tornado server and close the browser window before the restart and then reload the page i won't run into that error and my connections are getting subscribed + on_message messages

UPDATE2

Too fast.... i could not reproduce the NS_ERROR_NOT_CONNECTED error again... but the swampdragon/tornado server gets keeping locked up when i reload often and then is not subscribing anymore

UPDATE3

I tried to do a workaround on subscribing not get it subscribed directly after the other connection subscribed but with 500ms time waiting between each subscribing channel. For now it looks kind of stable...

blodone commented 9 years ago

So ... for one day it seems that its now working with the delayed subscribes without problems. If i disable the timeout and let it subscribe right next to each other, the tornado subscribe hangs up and gets irresponsive

UPDATE It was not the solution... i was thinking of that and then it happened, the log file encountered no on_message and the subscription was lost and not publishing after a reload... A few server restarts with the NS_ERROR_NOT_CONNECTED error comming up again .... later .... its working again without problems

blodone commented 9 years ago

As for now, i have coded a tornado-HA which subscribes at the swampdragon/tornado and listens for publish on_message + submits every 10 seconds a save which leads to a publish. If the publish is broken it restarts the swampdragon server (controlled by supervisor). For now i can work with it