ledgetech / ledgetech/lua-resty-http

Set_keepalive alway return "closed while sending to client"

Open
#323 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
2.1k
Forks
630
PR merge metrics
No merged PRs in 30d

Description

We plan to use Lua code blocks to call external services to record some logs in Nginx services, But the pressure test found poor performance and high latency.

I found that http.set_keepalive has error response and keepalive is not taking effect. I have pasted some code as follow, could you please help me analyze it?

Error response:
*1375 [lua] content_by_lua(nginx.conf:97):27: failed to set keepalive: closed while sending to client, client: 192.168.71.11, server: _, request: "POST /v2/models/aiml_model/infer HTTP/1.1", host: "aiplatform.dev51.cbf.dev.paypalinc.com-shadow"

`

   location / {
        mirror /mirror1;
        resolver 192.168.36.10 valid=10s;
        proxy_pass  http://backends;
        proxy_method $request_method;
        mirror_request_body on;
        proxy_pass_request_body on;

        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        content_by_lua_block {
            local http = require "resty.http"
            local ngx_log = ngx.log
            local ngx_ERR = ngx.ERR
            local httpc = http.new()
            httpc:set_timeout(5000)

            local url = "https://aiplatform.dev52.cbf.dev.paypalinc.com/bizlogging/insert?model_id=model_id"
            local body = '{"metadata_schema": ["request_body"],"variable_schema": ["response_body"]}'
            local headers = {
                ["Content-Type"] = "application/json",
                ["accept"] = "*/*",
            }

           local res, err = httpc:request_uri(url, {
               method = "POST",
               body = body,
               headers = headers,
               ssl_verify = false,
               timeout = 1000,
           })

           ngx_log(ngx_ERR, "success to request: ", res.status)

            local ok, err1 = httpc:set_keepalive(60000, 100)
            if not ok then
                ngx_log(ngx_ERR, "failed to set keepalive: ", err1)
            end
        }
    }`

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 by reproducing the shown OpenResty configuration and tracing the httpc:request_uri call through httpc:set_keepalive. Check the reported “closed while sending to client” response and determine the conditions under which keepalive fails; done means a confirmed cause and a project-appropriate fix or documented resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
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.