Pipeline support for ngx.req.socket(true)?

83 views
Skip to first unread message

Piers O'Hanlon

unread,
May 13, 2019, 11:21:27 AM5/13/19
to openresty-en
Hi,

I've been trying to use ngx.req.socket(true) sockets for pipelined requests but I cannot get it to respond to more than the first pipelined request (/pipelinefail) - as can be seen the example (/pipelinepass) it works fine with just ngx.req.socket(). I wasn't sure if I was missing something, or if the current stable version of OpenResty (or nginx) does not support it yet?

The basic example config:

        location = /pipelinefail {
        content_by_lua '
            ngx.status = 101
            ngx.req.read_body()
            local sock, err = ngx.req.socket(true)
            if not sock then
                ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
                return
            end
            local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\nhello")
            if not ok then
                ngx.log(ngx.ERR, "failed to send: ", err)
                return
            end
        ';
        }

        location = /pipelinepass {
        content_by_lua '
            ngx.status = 101
            ngx.req.read_body()
            local sock, err = ngx.req.socket()
            if not sock then
                ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
                return
            end
            local ok, err = ngx.say("200 OK\\r\\nContent-Length: 5\\r\\n\\r\\nhello")
            if not ok then
                ngx.log(ngx.ERR, "failed to send: ", err)
                return
            end
        ';
        }

Any comments/help welcome.

Thanks.

Piers O'Hanlon

unread,
May 14, 2019, 7:20:11 AM5/14/19
to openresty-en
I realise my examples aren't the best (there's left over cruft from other test code), but what I'm most interested in is providing for persistent connections (pipelining would be good too) - If one runs test15 from OpenResty:

It can be seen that if a client sends more than one request (with header Connection: keep-alive) down the same TCP connection only the first one is acted on. It works fine if the client closes the connection and opens a new each time. I'm wondering if there's anything missing from that test code to support persistent connections or if OpenResty 1.13.6 doesn't support it?

Thanks again for any input.
Reply all
Reply to author
Forward
0 new messages