openresty stream模块 使用lua-resty-http的问题

131 views
Skip to first unread message

kitestar

unread,
Jul 30, 2021, 3:53:23 AM7/30/21
to openresty

系统环境以及版本信息:
    Openresty 1.19.3.1, ngx_stream_lua-0.0.9
    CentOS Linux release 7.9.2009 (Core)

     Lua HTTP client cosocket driver for OpenResty / ngx_lua. 
考虑到reqeust_uri方法没有使用http特有的api例如 ngx_req.get_headers, 
在stream模块中尝试使用这个http client库,   但是经常出现'busy reading' 错误, 无法接收到最后一个结尾chunk 数据 "0\r\n\r\n"
 
在http库中打断点日志 

WechatIMG55258.jpeg

WechatIMG55259.jpeg


 日志输出: 
15:08:29 [error] stream [lua] http.lua:440: --------------------- before read line while prereading client data
15:08:29 [error] stream [lua] http.lua:442: +++++++++++++++++++++ after read line:177 while prereading client data
15:08:29 [error] stream [lua] http.lua:564: read_body(): ====== chunk 375 ,  err:nil while prereading client data
15:08:29 [error] stream [lua] http.lua:440: --------------------- before read line while prereading client data
15:08:29 [error] stream [lua] http.lua:564: read_body(): ====== chunk nil ,  err:nil while prereading client data
15:08:29 [error] stream [lua] http.lua:940: request_uri():  -------------------------  socket busy reading while prereading client data

lua-resty-http这个库在 新建的lua协程中 sock:receive 
sock:receive 方法还没返回之前, 也就是用户协程还未yeild, 另一头reader就收到了返回值,   chunk和err都是nil 
实际chunk receive 还没 收到end chunk,  后续sock:setkeepalive 因为 sock:receive 还未返回导致 busy reading   


请教下各位,  http模块使用这个库就没有这个问题, 为什么在stream模块中 在新创建的coroutine中, sock:receive 就不行了 

kurapi...@gmail.com

unread,
Aug 3, 2021, 10:28:39 PM8/3/21
to openresty
stream里面socket读取的数据和结构都和具体协议有关,你等于用固定的http协议去读其它协议的内容,OR的sock直接处理stream已经很方便了。没必要特意用库,或者找对应协议的库。
Reply all
Reply to author
Forward
0 new messages