Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx.redirect 307 makes srcache_fetch fail #87

Open
kapouer opened this issue Nov 13, 2020 · 3 comments
Open

ngx.redirect 307 makes srcache_fetch fail #87

kapouer opened this issue Nov 13, 2020 · 3 comments

Comments

@kapouer
Copy link
Contributor

kapouer commented Nov 13, 2020

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
@kapouer
Copy link
Contributor Author

kapouer commented Nov 13, 2020

And if i tell srcache to not cache 307 responses, it doesn't fail either.

@kapouer
Copy link
Contributor Author

kapouer commented Nov 14, 2020

My bad, the previous log was when i disable caching of 307 responses.
This is when i do default redirects (302)

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

headers more header filter, uri "/mypath"
posix_memalign: 000055F9CE825470:4096 @16
lua header filter for user lua code, uri "/mypath"
http cleanup add: 000055F9CE78FA88
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
http2 output header: ":status: 302"
http2 output header: "server: nginx"
http2 output header: "date: Sat, 14 Nov 2020 21:02:31 GMT"
http2 output header: "content-type: text/html"
http2 output header: "content-length: 138"
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 000055F9CE825668: len:155 fin:0
http cleanup add: 000055F9CE825770
http2 frame out: 000055F9CE825668 sid:1 bl:1 len:155
SSL buf copy: 9
SSL buf copy: 155
http2:1 HEADERS frame 000055F9CE825668 was sent
http2 frame sent: 000055F9CE825668 sid:1 bl:1 len:155
http output filter "/mypath?"
http copy filter: "/mypath?"
http script var: "1"
srcache_store skipped due to the true value in srcache_store_skip: "1"
lua capture body filter, uri "/mypath"
http postpone filter "/mypath?" 000055F9CE8258B0
http brotli filter

@kapouer
Copy link
Contributor Author

kapouer commented Nov 14, 2020

(edited to remove timestamps). So i diffed them and got:
this works

srcache store header HTTP/1.1 302 Moved Temporarily
Content-Type: text/html
Location: https://test3.localhost.localdomain:17443/mypath

headers more header filter, uri "/mypath"

this does not

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"

The first line in the second block does not carry "Temporary Redirect"
Ho ! "Temporary Redirect".lengh == 18 ;)
I will investigate further.

kapouer added a commit to kapouer/srcache-nginx-module that referenced this issue Nov 15, 2020
kapouer added a commit to kapouer/srcache-nginx-module that referenced this issue Jun 23, 2022
kapouer added a commit to kapouer/srcache-nginx-module that referenced this issue Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant