openresty / lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
https://openresty.org/
11.33k stars 2.03k forks source link

bugfix: respect max retry after using balancer pool #2331

Closed tzssangglass closed 4 months ago

tzssangglass commented 4 months ago

In the balancer phase, when obtaining a connection from the upstream connection pool, the cached attribute of the peer connection is set to 1(pc->cached = 1;), indicating that the connection is obtained from the cache.

If an error occurs during the use of this connection, such as "upstream prematurely closed connection" the system will increase the tries attribute of the peer connection by executing u->peer.tries++.

This PR restores tries by callbacks to the balancer when u->peer.tries++ is unexpectedly set.

I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project.

tzssangglass commented 4 months ago

sister PR:

zhuizhuhaomeng commented 4 months ago
/home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c: In function ‘ngx_http_lua_balancer_notify_peer’:
/home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c:747:17: error: ‘NGX_HTTP_UPSTREAM_NOTIFY_CACHED_CONNECTION_ERROR’ undeclared (first use in this function); did you mean ‘NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL’?
  747 |     if (type == NGX_HTTP_UPSTREAM_NOTIFY_CACHED_CONNECTION_ERROR) {
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL
/home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c:747:17: note: each undeclared identifier is reported only once for each function it appears in
tzssangglass commented 4 months ago

/home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c: In function ‘ngx_http_lua_balancer_notify_peer’: /home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c:747:17: error: ‘NGX_HTTP_UPSTREAM_NOTIFY_CACHED_CONNECTION_ERROR’ undeclared (first use in this function); did you mean ‘NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL’? 747 | if (type == NGX_HTTP_UPSTREAM_NOTIFY_CACHED_CONNECTION_ERROR) { | ^~~~~~~~~~~~ | NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL /home/travis/build/openresty/lua-nginx-module/src/ngx_http_lua_balancer.c:747:17: note: each undeclared identifier is reported only once for each function it appears in

https://github.com/openresty/openresty/pull/986/files