api7 / api7/apisix-nginx-module

About settimeouts doesn't work when i use read

Open
#73 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
45
Forks
25
Avg merge
1h 34m
Merged PRs (30d)
1

Description

About settimeouts doesn't work when i use read

If I connect to the server but I don't send any data

The read API does not timeout and return timeout

I read the source code(resty.apisix.stream.xrpc.socket.lua) and found that it wait here at [coroutine._yield], but I did not find the location of the call to [coroutine.resume].
If we use [coroutine._yield] is required to use [coroutine.resume] back here, I wonder if my understanding is wrong

Reproduction code:

preread_by_lua_block {

local ffi = require("ffi")
local ffi_str = ffi.string
local xrpc_socket = require("resty.apisix.stream.xrpc.socket")

local downstream=xrpc_socket.downstream.socket()

downstream:settimeouts(3*1000, 3*1000, 3*1000)

ngx.log(ngx.ERR,"start read")
local data, err = downstream:read(5)

if not data then
	ngx.log(ngx.ERR,"read err:",err)
else
	local s = ffi.string(data, 5)
	ngx.log(ngx.ERR,"recv data:",data)
end

}

$ openresty -V
nginx version: openresty/1.21.4.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1o 3 May 2022
TLS SNI support enabled
configure arguments: --prefix=/app/openresty/nginx --with-cc-opt='-O2 -DAPISIX_BASE_VER=latest -DNGX_GRPC_CLI_ENGINE_PATH=/app/openresty/libgrpc_engine.so -DNGX_HTTP_GRPC_CLI_ENGINE_PATH=/app/openresty/libgrpc_engine.so' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.33 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.09 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.9 --add-module=../ngx_stream_lua-0.0.11 --with-ld-opt='-Wl,-rpath,/app/openresty/luajit/lib -Wl,-rpath,' --add-module=/app/install/openresty-1.21.4.1/../mod_dubbo-master --add-module=/app/install/openresty-1.21.4.1/../ngx_multi_upstream_module-master --add-module=/app/install/openresty-1.21.4.1/../apisix-nginx-module-main --add-module=/app/install/openresty-1.21.4.1/../apisix-nginx-module-main/src/stream --add-module=/app/install/openresty-1.21.4.1/../apisix-nginx-module-main/src/meta --add-module=/app/install/openresty-1.21.4.1/../lua-var-nginx-module-master --add-module=/app/install/openresty-1.21.4.1/../grpc-client-nginx-module-main --with-poll_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-openssl=/app/install/openssl-1.1.1o --with-openssl-opt=-g --with-stream --with-http_ssl_module

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with resty.apisix.stream.xrpc.socket.lua and trace the coroutine._yield path used by downstream.socket():read(5), comparing it with the settimeouts(3*1000, ...) reproduction. Run the supplied preread_by_lua_block case; done means an idle read returns the timeout error.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.