Skip to content

Commit

Permalink
fix continuous update dyups upstream connections accumulation when up…
Browse files Browse the repository at this point in the history
…stream keepalive on
  • Loading branch information
乃斌 committed Aug 28, 2024
1 parent 04baff4 commit a35404d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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);
}
}
}


0 comments on commit a35404d

Please sign in to comment.