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

fix continuous update dyups upstream connections accumulation when up… #1956

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/ngx_http_upstream_dyups_module/ngx_http_dyups.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ extern ngx_flag_t ngx_http_dyups_api_enable;
extern ngx_dyups_add_upstream_filter_pt ngx_dyups_add_upstream_top_filter;
extern ngx_dyups_del_upstream_filter_pt ngx_dyups_del_upstream_top_filter;

extern void ngx_http_upstream_keepalive_clear_cache_connections(ngx_http_upstream_srv_conf_t *us);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,8 @@ ngx_dyups_mark_upstream_delete(ngx_http_dyups_srv_conf_t *duscf)
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
"[dyups] delete upstream \"%V\"", &duscf->upstream->host);

ngx_http_upstream_keepalive_clear_cache_connections(uscf);

ngx_dyups_del_upstream_top_filter(umcf, uscf);

us = uscf->servers->elts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,30 @@ ngx_http_upstream_keepalive_timeout(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_OK;
}

void
ngx_http_upstream_keepalive_clear_cache_connections(ngx_http_upstream_srv_conf_t *us) {
if (us == NULL) {
return;
}
ngx_http_upstream_keepalive_srv_conf_t *kcf;
ngx_http_upstream_keepalive_cache_t *item;
ngx_queue_t *q, *cache;
kcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_keepalive_module);
if (kcf == NULL || kcf->max_cached == 0) {
return;
}
cache = &kcf->cache;
if (cache == NULL || cache->prev == NULL || cache->next == NULL) {
return;
}
kcf->timeout = 0;
for (q = ngx_queue_head(cache); q != ngx_queue_sentinel(cache); q = ngx_queue_next(q)) {
item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
if (item->connection && item->connection->read && item->connection->read->timer_set) {
ngx_del_timer(item->connection->read);
ngx_add_timer(item->connection->read, kcf->timeout);
}
}
}


65 changes: 65 additions & 0 deletions tests/nginx-tests/tengine-tests/dyups.t
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,71 @@ unlike(mhttp_get('/', 'dyhost', 8080), qr/8088/m, '5/ 5 11:04:42 2014');
$t->stop();
unlink("/tmp/dyupssocket");

##############################################################################

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

worker_processes 1;

events {
accept_mutex off;
}

http {
%%TEST_GLOBALS_HTTP%%

resolver_timeout 500ms;

server {
listen 8080;

location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://$host;
}
}

server {
listen 8088;
location / {
return 200 "8088";
}
}

server {
listen 8089;
location / {
return 200 "8089";
}
}

server {
listen 8081;
location / {
dyups_interface;
}
}
}
EOF

mrun($t);

like(mhttp_post('/upstream/dyhost', 'keepalive 32; keepalive_timeout 50s; server 127.0.0.1:8088; server 127.0.0.1:8089;', 8081), qr/success/m, '2024-08-28 14:37:20');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:23');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:26');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:29');
like(mhttp_post('/upstream/dyhost', 'keepalive 32; keepalive_timeout 60s; server 127.0.0.1:8088; server 127.0.0.1:8089;', 8081), qr/success/m, '2024-08-28 14:37:32');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:35');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:38');
like(mhttp_get('/', 'dyhost', 8080), qr/8088|8089/m, '2024-08-28 14:37:41');

$t->stop();

###############################################################################
# test ssl session reuse

Expand Down