为什么设置了proxy_next_upstream off 之后还会尝试转发请求

408 views
Skip to first unread message

ywsa...@gmail.com

unread,
Nov 5, 2013, 2:41:46 AM11/5/13
to open...@googlegroups.com
hi, all

    最近openresty出现死循环,死在get upstream peer上,也发现一个奇怪的问题,在设置了proxy_next_upstream off 之后,upstream还是会尝试将请求转发到其它服务器,下面是死循环打印的调用栈
#0  0x00000000004bb91c in ngx_http_upstream_get_consistent_hash_peer (pc=0x5943bc8,
    data=<value optimized out>)
    at /data0/workshop/tools/ngx_http_consistent_hash-0b75d6d/ngx_http_upstream_consistent_hash_module.c:170
#1  0x0000000000479066 in ngx_http_upstream_get_keepalive_peer (pc=0x57eee20,
    data=<value optimized out>) at src/http/modules/ngx_http_upstream_keepalive_module.c:227
#2  0x000000000042d552 in ngx_event_connect_peer (pc=0x57eee20) at src/event/ngx_event_connect.c:25

#3  0x0000000000451586 in ngx_http_upstream_connect (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1121
#4  0x0000000000451c11 in ngx_http_upstream_next (r=0x67cc018, u=0x5943bb8, ft_type=2)
    at src/http/ngx_http_upstream.c:2953
#5  0x0000000000451e45 in ngx_http_upstream_process_header (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1582
#6  0x0000000000451455 in ngx_http_upstream_send_request (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1449
#7  0x0000000000451a21 in ngx_http_upstream_connect (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1234
#8  0x0000000000451c11 in ngx_http_upstream_next (r=0x67cc018, u=0x5943bb8, ft_type=2)
    at src/http/ngx_http_upstream.c:2953
#9  0x0000000000451e45 in ngx_http_upstream_process_header (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1582
#10 0x0000000000451455 in ngx_http_upstream_send_request (r=0x67cc018, u=0x5943bb8)
    at src/http/ngx_http_upstream.c:1449
#11 0x0000000000451a21 in ngx_http_upstream_connect (r=0x67cc018, u=0x5943bb8)

    at src/http/ngx_http_upstream.c:1234
#12 0x0000000000453408 in ngx_http_upstream_init_request (r=0x67cc018)
    at src/http/ngx_http_upstream.c:645
#13 0x00000000004534ca in ngx_http_upstream_init (r=0x67cc018) at src/http/ngx_http_upstream.c:446
有几个问题:
1、我的理解是红色部分应该就是失败之后重新尝试连其它服务器的过程,是这样的吗?
2、很奇怪的是蓝色部分的 pc 参数居然不一样,这是为什么呢

ps:openresty版本为1.2.3.8 ,consistent_hash 模块使用的是 https://github.com/sduwangning/ngx_http_consistent_hash 这个代码
其中upstream 配置如下
upstream sampleurl {
        consistent_hash $hash_str;

        server 10.77.6.77:8080;
        server 10.77.6.78:8080;
        server 10.77.6.82:8080;
        server 10.77.6.83:8080;

        keepalive 10;
}
死循环问题出现过几次了,重启服务后会正常运行

找了几天原因未果,望各位大牛能给我点提示信息,应该从哪里入手找这个原因

Yichun Zhang (agentzh)

unread,
Nov 5, 2013, 3:03:53 PM11/5/13
to openresty
Hello!

2013/11/4 ywsample:
> 最近openresty出现死循环,死在get upstream peer上,也发现一个奇怪的问题,在设置了proxy_next_upstream
> off 之后,upstream还是会尝试将请求转发到其它服务器,下面是死循环打印的调用栈
> #0 0x00000000004bb91c in ngx_http_upstream_get_consistent_hash_peer
> (pc=0x5943bc8,
> data=<value optimized out>)
> at
> /data0/workshop/tools/ngx_http_consistent_hash-0b75d6d/ngx_http_upstream_consistent_hash_module.c:170

从你提供的调用栈轨迹看,是死循环在你使用的 ngx_http_consistent_hash 模块中了。这个模块中有一个 for (;;)
{ ... } 循环,当 !(chp->tried[n] & m) 这个条件为假时,这个循环就无限执行了。

由于这个第三方模块并不是标准 openresty
软件包的一部分,所以原则上我并不会对这个模块提供技术支持。建议直接联系你用的这个模块分支的维护者,sduwangning.

> 有几个问题:
> 1、我的理解是红色部分应该就是失败之后重新尝试连其它服务器的过程,是这样的吗?

是的。

> 2、很奇怪的是蓝色部分的 pc 参数居然不一样,这是为什么呢
>

如果你使用的是 x86_64 体系结构,则调用栈上各个函数帧的参数值出现垃圾值是很正常的事情。毕竟根据 x86_64 的
ABI,函数调用的前几个参数都是直接通过寄存器传递的,并不压栈,所以在更深的函数帧里可能会临时改写掉上面的函帧的参数所对应的寄存器。

>
> ps:openresty版本为1.2.3.8 ,

值得一提的是,最新的 ngx_openresty 稳定版是 1.4.2.8,最新的主线版是 1.4.3.1. 建议升级之。

> consistent_hash 模块使用的是
> https://github.com/sduwangning/ngx_http_consistent_hash 这个代码

你可以直接在他的 fork 里新建 github issue 向他报告 :) 我现在并没有时间仔细分析他的这个分支的代码。

Regards,
-agentzh

ywsa...@gmail.com

unread,
Nov 5, 2013, 9:01:03 PM11/5/13
to open...@googlegroups.com
好的,多谢春哥

在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:

ywsa...@gmail.com

unread,
Nov 6, 2013, 1:14:56 AM11/6/13
to open...@googlegroups.com
还有一问题,为什么在设置了proxy_next_upstream off之后还会尝试重新连其它服务器

在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:
在 2013年11月6日星期三UTC+8上午4时03分53秒,agentzh写道:

Yichun Zhang (agentzh)

unread,
Nov 6, 2013, 11:26:32 PM11/6/13
to openresty
Hello!

2013/11/5 ywsample:
> 还有一问题,为什么在设置了proxy_next_upstream off之后还会尝试重新连其它服务器
>

最大的可能是你把 proxy_next_upstream off 放错了地方。你需要确保这一行配置能为你配置 proxy_pass 的
location 所正确继承。

Regards,
-agentzh

Weibin Yao

unread,
Nov 6, 2013, 11:50:02 PM11/6/13
to open...@googlegroups.com
针对后端长连接,如果后端出现直接关连接这种错误的时候,nginx会出现无条件
重试的问题。Tengine专门针对这个问题,还加了一个 retry_cached_connection
指令来关闭
(https://github.com/alibaba/tengine/commit/7035b9508cf93ec82928cd74e475743773afb962
)

--
Thanks
-YWB

ywsample

unread,
Nov 7, 2013, 10:12:42 PM11/7/13
to open...@googlegroups.com
谢谢 weibin,的确是发生了这种情况,这是nginx有意为知的吗?又或者是一个bug


2013/11/7 Weibin Yao <yaow...@gmail.com>


--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@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



--
ywsample :)

Reply all
Reply to author
Forward
0 new messages