UDP协程内接收写入table会出现大量丢包

48 views
Skip to first unread message

Chan WingChung

unread,
Sep 12, 2022, 5:14:35 AM9/12/22
to openresty
UDP协程内接收写入table会出现大量丢包
local sock_, sock_err_ = ngx.req.socket()
while sock_ do
    local _data_ = sock_:receive(65535)
    if data_ ~= nil then
        table.insert(cache_data_, data_)
    end
    ngx.sleep(0.01)
end

Chan WingChung

unread,
Sep 13, 2022, 4:24:06 AM9/13/22
to openresty
已经发现这个神奇的bug是怎么来的,在 receive里面的buffer有bug,如果一次会话的总容量超过buffer,那就会爆掉。

Junlong li

unread,
Sep 14, 2022, 9:01:43 AM9/14/22
to openresty
一个udp包的大小最多是64k。原来的代码限制为1500还是8k,因此如果单个报文的大小超过上面的限制值就被截断。你说的超过buffer具体哪个buffer?

Chan WingChung

unread,
Sep 15, 2022, 2:23:01 PM9/15/22
to openresty
但是TCP当进行receive之后,数据会被取走,不会爆。

Junlong li

unread,
Sep 18, 2022, 9:21:37 PM9/18/22
to openresty

你能给一个可以复现的完整例子吗? 另外你为什么要调用ngx.sleep呢?

Chan WingChung

unread,
Sep 20, 2022, 3:37:36 AM9/20/22
to openresty

查到问题了,不能用while, receive只能读一次,第二次读就是nil
Reply all
Reply to author
Forward
0 new messages