Skip to content

Commit ccf33db

Browse files
committed
fix(vars): remove request_time from default indexed variables
The request_time variable was previously indexed by default in the NGINX module. However, this behavior is problematic because request_time is a dynamic value that changes over the request lifecycle. Indexing it causes the first access to cache its value, leading to incorrect results for subsequent accesses. This issue is particularly impactful in Active Tracing, where request_time is used during the log phase. The cached value can result in inaccurate tracing data. This is because the first access to this variable will cache it and subsequent accesses will use the cached value. This commit removes request_time from the list of default indexed variables to ensure its value is always retrieved dynamically. Corresponding test cases have been updated to reflect this change. Fix KAG-6868
1 parent 7a7c074 commit ccf33db

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ concurrency:
99
jobs:
1010
tests:
1111
name: Lint
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313

1414
steps:
1515
- name: Checkout source code

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ index *commonly used variables* as follows:
113113
- `$remote_port`
114114
- `$request_length`
115115
- `$request_method`
116-
- `$request_time`
117116
- `$request_uri`
118117
- `$scheme`
119118
- `$server_addr`

src/ngx_http_lua_kong_var_index.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ static ngx_str_t default_vars[] = {
7171
/* ngx_string("request"), */
7272
ngx_string("request_length"),
7373
ngx_string("request_method"),
74-
ngx_string("request_time"),
7574
ngx_string("request_uri"),
7675
ngx_string("scheme"),
7776
ngx_string("server_addr"),

t/006-default_indexed-var.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Test::Nginx::Socket::Lua;
99

1010
repeat_each(2);
1111

12-
plan tests => repeat_each() * (blocks() * 8) + 14;
12+
plan tests => repeat_each() * (blocks() * 8) + 12;
1313

1414
#no_diff();
1515
#no_long_string();
@@ -205,7 +205,6 @@ get variable value '666' by index
205205
ngx.say(ngx.var.request_method, " ",
206206
ngx.var.request_length, " ",
207207
ngx.var.request_uri, " ",
208-
ngx.var.request_time, " ",
209208
ngx.var.server_addr, " ",
210209
ngx.var.server_port
211210
)
@@ -214,12 +213,11 @@ get variable value '666' by index
214213
--- request
215214
GET /test
216215
--- response_body
217-
GET 58 /test 0.000 127.0.0.1 1984
216+
GET 58 /test 127.0.0.1 1984
218217
--- error_log
219218
get variable value 'GET' by index
220219
get variable value '58' by index
221220
get variable value '/test' by index
222-
get variable value '0.000' by index
223221
get variable value '127.0.0.1' by index
224222
get variable value '1984' by index
225223
--- no_error_log

0 commit comments

Comments
 (0)