Skip to content

Commit a35404d

Browse files
author
乃斌
committed
fix continuous update dyups upstream connections accumulation when upstream keepalive on
1 parent 04baff4 commit a35404d

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

modules/ngx_http_upstream_dyups_module/ngx_http_dyups.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ extern ngx_flag_t ngx_http_dyups_api_enable;
2727
extern ngx_dyups_add_upstream_filter_pt ngx_dyups_add_upstream_top_filter;
2828
extern ngx_dyups_del_upstream_filter_pt ngx_dyups_del_upstream_top_filter;
2929

30+
extern void ngx_http_upstream_keepalive_clear_cache_connections(ngx_http_upstream_srv_conf_t *us);
31+
3032
#endif

modules/ngx_http_upstream_dyups_module/ngx_http_dyups_module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,8 @@ ngx_dyups_mark_upstream_delete(ngx_http_dyups_srv_conf_t *duscf)
17171717
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
17181718
"[dyups] delete upstream \"%V\"", &duscf->upstream->host);
17191719

1720+
ngx_http_upstream_keepalive_clear_cache_connections(uscf);
1721+
17201722
ngx_dyups_del_upstream_top_filter(umcf, uscf);
17211723

17221724
us = uscf->servers->elts;

modules/ngx_http_upstream_keepalive_module/ngx_http_upstream_keepalive_module.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,30 @@ ngx_http_upstream_keepalive_timeout(ngx_conf_t *cf, ngx_command_t *cmd,
11051105
return NGX_CONF_OK;
11061106
}
11071107

1108+
void
1109+
ngx_http_upstream_keepalive_clear_cache_connections(ngx_http_upstream_srv_conf_t *us) {
1110+
if (us == NULL) {
1111+
return;
1112+
}
1113+
ngx_http_upstream_keepalive_srv_conf_t *kcf;
1114+
ngx_http_upstream_keepalive_cache_t *item;
1115+
ngx_queue_t *q, *cache;
1116+
kcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_keepalive_module);
1117+
if (kcf == NULL || kcf->max_cached == 0) {
1118+
return;
1119+
}
1120+
cache = &kcf->cache;
1121+
if (cache == NULL || cache->prev == NULL || cache->next == NULL) {
1122+
return;
1123+
}
1124+
kcf->timeout = 0;
1125+
for (q = ngx_queue_head(cache); q != ngx_queue_sentinel(cache); q = ngx_queue_next(q)) {
1126+
item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
1127+
if (item->connection && item->connection->read && item->connection->read->timer_set) {
1128+
ngx_del_timer(item->connection->read);
1129+
ngx_add_timer(item->connection->read, kcf->timeout);
1130+
}
1131+
}
1132+
}
1133+
1134+

0 commit comments

Comments
 (0)