openresty / openresty/lua-nginx-module

Why cosocket read timeout error when receive response on time?

Open
#1,904 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

i would like to send data to server, and receive process result, but i got some lua tcp socket read timed out error,
The error is as follows:

2021/07/19 04:05:33 [error] 134162#0: *383692285 lua tcp socket read timed out, client: 183.84.4.102, server: _, request: "GET /ping HTTP/1.1", 
2021/07/19 04:05:56 [error] 134166#0: *383066134 lua tcp socket read timed out, client: 111.199.189.186, server: _, request: "POST /v1/client/heartbeat HTTP/1.1", 
2021/07/19 04:06:57 [error] 134166#0: *383767683 lua tcp socket read timed out, client: 124.126.141.88, server: _, request: "POST /desktop/v1/client/heartbeat HTTP/1.1", 
2021/07/19 04:08:45 [error] 134166#0: *383850419 lua tcp socket read timed out, client: 122.224.227.210, server: _, request: "GET /cs/message/latest HTTP/1.1", 
--More--

my code is as follows, which is called in access_by_lua_block:

function Connector._query_tcp(self, packed_data)
    local sock = ngx.socket.tcp()
    sock:settimeouts(15, 5, 20)

    local ok, err = sock:connect(self.server, self.port)
    if not ok then
        return nil, err, "connect"
    end

    local ok, err = sock:send(packed_data..self.boundary)
    if not ok then
        return nil, err, "send"
    end

    local resp_data, err = sock:receiveuntil(self.boundary)()
    if not resp_data then
        return nil, err, "read"
    end
    ok, err = sock:setkeepalive(60000, 5000)
    return resp_data, nil, ""
end

other setting of nginx:
tcp_nodelay on;

i use tcpdump to capture the packets, and use wireshark to find the timeout reqs with reqid. From the result, i find my network card receive process result from server immediately, the timecost is less then 2 milliseconds, my settings of read timeout is 20 milliseconds, this confuse me much
image

Any help is precious!

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 the cosocket timeout behavior around ngx.socket.tcp(), settimeouts(), and receiveuntil(), then compare it with the access_by_lua_block example and the tcpdump/Wireshark timestamps provided. Done means determining whether the reported timing is expected behavior or a reproducible module bug, with a focused reproduction if applicable.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.