如何早点结束慢链接

162 views
Skip to first unread message

魏海通

unread,
Jul 24, 2018, 5:09:13 AM7/24/18
to openresty
在body_filter 阶段判断速度,如果低于配置的阈值就结束链接:return ngx.ERROR

但是用这种方法断开时,还会继续发送队列里面的数据,请问如何才能丢掉发送缓存区的数据,尽早结束链接?

Hadals Yang

unread,
Jul 24, 2018, 9:16:00 PM7/24/18
to openresty
返回444 行不行?

tokers

unread,
Jul 24, 2018, 9:52:09 PM7/24/18
to openresty
Hello!

可以了解下 ngx.arg 的用法,https://github.com/openresty/lua-nginx-module#toc105

在 body_filter 阶段只要你把 ngx.arg[2] 设置成 true,就能结束往下游发送数据了。

魏海通

unread,
Jul 25, 2018, 5:52:41 AM7/25/18
to openresty
谢谢,444试了,还是会调用close,这样TCP缓冲区还是会有数据发送出去吧。是有直接RST的做法?

在 2018年7月25日星期三 UTC+8上午9:16:00,Hadals Yang写道:
返回444 行不行?

魏海通

unread,
Jul 25, 2018, 5:54:30 AM7/25/18
to openresty
这种情况TCP层应该是CLOSE,在 ngx.arg[2] 设置成 true 前的数据,没有发送的还是继续发送。

在 2018年7月25日星期三 UTC+8上午9:52:09,tokers写道:

Zexuan Luo

unread,
Jul 25, 2018, 6:14:51 AM7/25/18
to open...@googlegroups.com
想跳过挥手阶段直接发送 RST,是没有现成的 API 可以用的。
也许你可以写一个 Nginx C 模块,设置给定 socket fd 的 SO_LINGER ,参考
https://github.com/nginx/nginx/blob/master/src/http/ngx_http_request.c#ngx_http_free_request
里面的做法。
> --
> --
> 邮件来自列表“openresty”,专用于技术讨论!
> 订阅: 请发空白邮件到 openresty...@googlegroups.com
> 发言: 请发邮件到 open...@googlegroups.com
> 退订: 请发邮件至 openresty+...@googlegroups.com
> 归档: http://groups.google.com/group/openresty
> 官网: http://openresty.org/
> 仓库: https://github.com/agentzh/ngx_openresty
> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

魏海通

unread,
Jul 25, 2018, 11:32:14 PM7/25/18
to openresty
多谢,我参考一下

在 2018年7月25日星期三 UTC+8下午6:14:51,Zexuan Luo写道:

Jianqiang Wang

unread,
Jul 27, 2018, 10:14:04 AM7/27/18
to openresty

魏海通

unread,
Jul 31, 2018, 7:10:40 AM7/31/18
to openresty
多谢,这个参数是全局的,如果客户是HTTP1.0 或者 服务器端主动关闭,在一定程度是丢掉了应该传输的数据。
我们的想法是做成请求级别的。


在 2018年7月27日星期五 UTC+8下午10:14:04,Jianqiang Wang写道:

Jianqiang Wang

unread,
Aug 1, 2018, 8:44:49 AM8/1/18
to openresty
Reply all
Reply to author
Forward
0 new messages