python - Socketio client switching to xhr-polling running with flask app -


i'm running socketio server flask app using gevent. namespace code here:

class conversationnamespace(basenamespace):     def __init__(self, *args, **kwargs):         request = kwargs.get('request', none)         if request:             self.current_app = request['current_app']             self.current_user = request['current_user']             super(conversationnamespace, self).__init__(*args, **kwargs)      def listener(self):         r = strictredis(host=self.current_app.config['redis_host'])         p = r.pubsub()         p.subscribe(self.current_app.config['redis_channel_conversation_key'] +     self.current_user.user_id)         conversation_keys = r.lrange(self.current_app.config['redis_conversation_list_key'] +                                  self.current_user.user_id, 0, -1)          # reverse conversations newest top.         conversation_keys.reverse()          # emit conversation history.         pipe = r.pipeline()         key in conversation_keys:             pipe.hgetall(self.current_app.config['redis_conversation_key'] + key)         self.emit(self.current_app.config['socketio_channel_conversation'] + self.current_user.user_id, pipe.execute())          # listen new conversations..         m in p.listen():             conversation = r.hgetall(self.current_app.config['redis_conversation_key'] + str(m['data']))             self.emit(self.current_app.config['socketio_channel_conversation'] +                   self.current_user.user_id, conversation)      def on_subscribe(self):         self.spawn(self.listener) 

what i'm noticing in app when first start socketio server (code below), clients able connect via websocket in firefox , chrome

#!vendor/venv/bin/python gevent import monkey monkey.patch_all() yellowtomato import app_instance import werkzeug.serving socketio.server import socketioserver  app = app_instance('sockets')  @werkzeug.serving.run_with_reloader def runserver():     socketioserver(('0.0.0.0', app.config['socket_port']), app,   resource='socket.io').serve_forever() runserver() 

after sometime (maybe hour or so), when try connect namespace via browser client, no longer communicates websocket rather xhr-polling. moreover, takes 20 seconds before first response comes server. gives end user perception things have become slow (but when rendering page on first subscibe, xhr polling happens , events pushed clients in timely fashion).

what triggering latency , how can assure clients connect using websockets.

figured out - running via command line in ssh session. ending sessions killed parent process causing gevent not work properly.

forking socketioserver process in screen session fixed problem


Comments