V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lolizeppelin
V2EX  ›  Python

eventlet 的 keepalive bug 咋解决 GOOGLE 上也搜捕到好办法

  •  
  •   lolizeppelin · 2018-03-21 14:43:25 +08:00 · 1372 次点击
    这是一个创建于 2200 天前的主题,其中的信息可能已经有所发展或是发生改变。
        def process_request(self, sock_params):
            # The actual request handling takes place in __init__, so we need to
            # set minimum_chunk_size before __init__ executes and we don't want to modify
            # class variable
            sock, address = sock_params
            proto = new(self.protocol)
            if self.minimum_chunk_size is not None:
                proto.minimum_chunk_size = self.minimum_chunk_size
            proto.capitalize_response_headers = self.capitalize_response_headers
            try:
                proto.__init__(sock, address, self)
            except socket.timeout:
                # Expected exceptions are not exceptional
                sock.close()
                # similar to logging "accepted" in server()
                self.log.debug('(%s) timed out %r' % (self.pid, address))
    

    BUG 就在上面, 绿色线程抛了一个假的 socket.timeout 错误 这里调用 sock close 无效, 先 shutdown 也没用....

    没有有高人知道怎么解决这个 bug

    1 条回复    2018-05-23 23:28:53 +08:00
    lolizeppelin
        1
    lolizeppelin  
    OP
       2018-05-23 23:28:53 +08:00
    今天闲着没事 终于把这个 bug 搞定了.....

    eventlet 的 HttpProtocol(继承自 python 的 BaseHTTPRequestHandler)在接收数据的时候为了方便
    通过 dup 把 socket 复制成了 file 对象
    由于 python2.6 的 BaseRequestHandler 没有在 finally 中调用 finish
    导致异常发生的时候没有关闭掉 dup 出来的 fd
    所以调用了 socket.close 并不能关闭 socket

    由于在 windows 环境一直是 2.7 的,导致一直没找到 bug.....
    真是蛋痛...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5041 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:36 · PVG 17:36 · LAX 02:36 · JFK 05:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.