Hello!
2012/12/19 Zheng Ping:
> Hi, all:
> 文档http://wiki.nginx.org/HttpLuaModule#lua_check_client_abort中有这么一段:;
> According to the current implementation, however, if the client closes the
> connection before the Lua code finishes reading the request body data via
> ngx.req.socket, then ngx_lua will neither stop all the running "light
> threads" nor call the user callback (if ngx.on_abort has been called).
> Instead, the reading operation on ngx.req.socket will just return the error
> message "client aborted" as the second return value (the first return value
> is surely nil).
>
> 我读了以后,理解晦涩,我的疑惑:
> 是不是即使用ngx.on_abort注册了客户端断开处理器,如果客户端的断开发生在ngx.req.socket读取数据尚未返回之前,ngx.on_abort注册的断开处理器也不会被调用?
是。
> 是不是此时我们只能通过判断ngx.req.socket的读取返回值才能完成客户端提前断开的清理工作?
是。你在通过 ngx.req.socket API 读取请求体数据时,总是应当通过检查函数返回值来进行恰当的错误处理。
这里存在此限制的一个主要原因是连接断开事件本身就是一个“读事件”,它会受到 socket 接收缓冲区中存在未读数据这种状态的干扰。
Best regards,
-agentzh