【发布时间】:2014-12-06 12:38:28
【问题描述】:
我的nginx配置是这样的:
server {
listen 80 so_keepalive=30m::;
location /wsgi {
uwsgi_pass uwsgicluster;
include uwsgi_params;
uwsgi_read_timeout 30000;
uwsgi_buffering off;
}
...
}
在我的蟒蛇中:
def application_(environ, start_response):
body = queue.Queue()
...
gevent.spawn(redis_wait, environ, body, channels)
return body
def redis_wait(environ, body, channels):
server = redis.Redis(connection_pool=REDIS_CONNECTION_POOL)
client = server.pubsub()
try:
for channel in channels:
client.subscribe(channel)
messages = client.listen()
for message in messages:
if message['type'] != 'message' and message['type'] != 'pmessage':
continue
body.put(message['data'])
finally:
client.unsubscribe()
client.close()
问题出现在客户端连接中断(网络连接突然丢失、应用程序终止等)时redis显示服务器上的连接仍然是打开的。我该如何解决?即使使用 so_keepalive,连接也不会被清理。我该如何解决这个问题?
编辑:我通过nginx_status 页面注意到活动连接计数在断开连接后确实下降。问题是 uwsgi 没有收到通知。
【问题讨论】: