Skip to content

ngx.redirect 307 makes srcache_fetch fail #87

@kapouer

Description

@kapouer

Hi,

using nginx 1.18 (+ openssl callback patch), http-lua 0.10.19, srcache 0.32, luajit-2.1.20201027 on a debian box,
when i use ngx.redirect(url) in access_by_lua on a working srcache config, everything's all right.
However if i use ngx.redirect(url, 307) i get

fetching key "test2.localhost.localdomain" in shared dict "myDomains"
shmtx lock
shmtx unlock
lua redirect to "https://test3.localhost.localdomain:17443/mypath" with code 307
lua resume returned 1
lua thread yielded
lua thread aborting request with status 307
lua request cleanup: forcible=0
http lua finalize threads
lua deleting light thread 00007FAC45F13F00 (ref 2)
lua caching unused lua thread 00007FAC45F13F00 (ref 2)
http finalize request: 307, "/mypath?" a:1, c:1
http special response: 307, "/mypath?"
http script var: "0"
srcache_store decides to store the response
srcache store header HTTP/1.1 307
Content-Type: text/html
Location: https://test3.localhost.localdomain:17443/mypath

srcache_fetch: buffer error when serializing the response header: -17 left, client: 127.0.0.1, server: _, request: "GET /mypath HTTP/2.0", host: "test2.localhost.localdomain:17443"
http finalize request: -1, "/mypath?" a:1, c:1
http terminate request count:1
http terminate cleanup count:1 blk:0
http posted request: "/mypath?"
http terminate handler count:1
http request count:1 blk:0
http2 close stream 1, queued 0, processing 1, pushing 0
http2 send RST_STREAM frame sid:1, status:2
http close request

and the client dies with

curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)

For comparison here's the log with a "standard" redirection:

fetching key "test2.localhost.localdomain" in shared dict "myDomains"
shmtx lock
shmtx unlock
lua redirect to "https://test3.localhost.localdomain:17443/mypath" with code 307
lua resume returned 1
lua thread yielded
lua thread aborting request with status 307
lua request cleanup: forcible=0
http lua finalize threads
lua deleting light thread 00007F9E5E1BADB0 (ref 2)
lua caching unused lua thread 00007F9E5E1BADB0 (ref 2)
http finalize request: 307, "/mypath?" a:1, c:1
http special response: 307, "/mypath?"
http script var: "0"
srcache_store bypassed because of unmatched status code 307 with srcache_store_statuses
headers more header filter, uri "/mypath"
lua header filter for user lua code, uri "/mypath"
http cleanup add: 000055A7B2533998
code cache lookup (key='header_filter_by_lua_nhli_46c354449c5f02150cba6fbbeb9a2288', ref=-1)
code cache miss (key='header_filter_by_lua_nhli_46c354449c5f02150cba6fbbeb9a2288', ref=-1)
fetching key "test2.localhost.localdomain" in shared dict "upcacheLocks"
shmtx lock
shmtx unlock
[lua] upcache.lua:50: response(): response key 'nil', client: 127.0.0.1, server: _, request: "GET /mypath HTTP/2.0", host: "test2.localhost.localdomain:17443"
lua capture header filter, uri "/mypath"
charset: "" > "utf-8"
http2 header filter
posix_memalign: 000055A7B2535AC0:4096 @16
http2 output header: ":status: 307"
http2 output header: "server: nginx"
http2 output header: "date: Fri, 13 Nov 2020 13:11:18 GMT"
http2 output header: "content-type: text/html; charset=utf-8"
http2 output header: "content-length: 164"
http2 output header: "location: https://test3.localhost.localdomain:17443/mypath"
http2 output header: "strict-transport-security: max-age=63072000; includeSubDomains; preload"
http2:1 create HEADERS frame 000055A7B2535BF8: len:166 fin:0
http cleanup add: 000055A7B2535D00
http2 frame out: 000055A7B2535BF8 sid:1 bl:1 len:166
SSL buf copy: 9
SSL buf copy: 166
http2:1 HEADERS frame 000055A7B2535BF8 was sent
http2 frame sent: 000055A7B2535BF8 sid:1 bl:1 len:166
http output filter "/mypath?"
http copy filter: "/mypath?"
lua capture body filter, uri "/mypath"
http postpone filter "/mypath?" 000055A7B2535E40

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions