[nginx] Switched to ngx_current_msec for lingering_time tracking.
Maxim Dounin
mdounin at mdounin.ru
Mon Jun 30 22:41:00 UTC 2025
details: http://freenginx.org/hg/nginx/rev/0e78991a58dd
branches:
changeset: 9382:0e78991a58dd
user: Maxim Dounin <mdounin at mdounin.ru>
date: Tue Jul 01 01:08:55 2025 +0300
description:
Switched to ngx_current_msec for lingering_time tracking.
This ensures that lingering time is not affected by system time changes
on platforms with monotonic time available.
diffstat:
src/http/ngx_http_request.c | 9 +++------
src/http/ngx_http_request.h | 2 +-
src/http/ngx_http_request_body.c | 4 +---
src/http/v2/ngx_http_v2.c | 6 ++----
src/http/v2/ngx_http_v2.h | 2 +-
5 files changed, 8 insertions(+), 15 deletions(-)
diffs (115 lines):
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2771,8 +2771,7 @@ ngx_http_finalize_connection(ngx_http_re
ngx_add_timer(r->connection->read, clcf->lingering_timeout);
if (r->lingering_time == 0) {
- r->lingering_time = ngx_time()
- + (time_t) (clcf->lingering_time / 1000);
+ r->lingering_time = ngx_current_msec + clcf->lingering_time;
}
}
@@ -3477,7 +3476,7 @@ ngx_http_set_lingering_close(ngx_connect
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (r->lingering_time == 0) {
- r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
+ r->lingering_time = ngx_current_msec + clcf->lingering_time;
}
#if (NGX_HTTP_SSL)
@@ -3557,7 +3556,7 @@ ngx_http_lingering_close_handler(ngx_eve
return;
}
- timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time();
+ timer = r->lingering_time - ngx_current_msec;
if ((ngx_msec_int_t) timer <= 0) {
ngx_http_close_request(r, 0);
return;
@@ -3586,8 +3585,6 @@ ngx_http_lingering_close_handler(ngx_eve
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- timer *= 1000;
-
if (timer > clcf->lingering_timeout) {
timer = clcf->lingering_timeout;
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -409,7 +409,7 @@ struct ngx_http_request_s {
ngx_http_request_body_t *request_body;
- time_t lingering_time;
+ ngx_msec_t lingering_time;
ngx_msec_t start_time;
ngx_uint_t method;
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -771,7 +771,7 @@ ngx_http_discarded_request_body_handler(
}
if (r->lingering_time) {
- timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time();
+ timer = r->lingering_time - ngx_current_msec;
if ((ngx_msec_int_t) timer <= 0) {
r->discarding_body = 0;
@@ -812,8 +812,6 @@ ngx_http_discarded_request_body_handler(
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- timer *= 1000;
-
if (timer > clcf->lingering_timeout) {
timer = clcf->lingering_timeout;
}
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -717,8 +717,7 @@ ngx_http_v2_lingering_close(ngx_connecti
}
if (h2c->lingering_time == 0) {
- h2c->lingering_time = ngx_time()
- + (time_t) (clcf->lingering_time / 1000);
+ h2c->lingering_time = ngx_current_msec + clcf->lingering_time;
}
#if (NGX_HTTP_SSL)
@@ -796,7 +795,7 @@ ngx_http_v2_lingering_close_handler(ngx_
return;
}
- timer = (ngx_msec_t) h2c->lingering_time - (ngx_msec_t) ngx_time();
+ timer = h2c->lingering_time - ngx_current_msec;
if ((ngx_msec_int_t) timer <= 0) {
ngx_http_close_connection(c);
return;
@@ -825,7 +824,6 @@ ngx_http_v2_lingering_close_handler(ngx_
clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
ngx_http_core_module);
- timer *= 1000;
if (timer > clcf->lingering_timeout) {
timer = clcf->lingering_timeout;
diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h
--- a/src/http/v2/ngx_http_v2.h
+++ b/src/http/v2/ngx_http_v2.h
@@ -162,7 +162,7 @@ struct ngx_http_v2_connection_s {
ngx_uint_t closed_nodes;
ngx_uint_t last_sid;
- time_t lingering_time;
+ ngx_msec_t lingering_time;
unsigned settings_ack:1;
unsigned table_update:1;
More information about the nginx-devel
mailing list