diff --git a/bundle/nginx-1.27.1/src/http/ngx_http_upstream.c b/bundle/nginx-1.27.1/src/http/ngx_http_upstream.c
index 1c771bc..3445bf2 100644
--- a/bundle/nginx-1.27.1/src/http/ngx_http_upstream.c
+++ b/bundle/nginx-1.27.1/src/http/ngx_http_upstream.c
@@ -2581,7 +2581,11 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
         }
 
         if (u->peer.tries > 1
+#if (NGX_HTTP_LUA_KONG)
+            && ((ngx_http_lua_kong_get_next_upstream_mask(r, u->conf->next_upstream) & mask) == mask)
+#else
             && ((u->conf->next_upstream & mask) == mask)
+#endif
             && !(u->request_sent && r->request_body_no_buffering)
             && !(timeout && ngx_current_msec - u->peer.start_time >= timeout))
         {
@@ -4451,7 +4455,12 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
     }
 
     if (u->peer.tries == 0
+#if (NGX_HTTP_LUA_KONG)
+        || ((ngx_http_lua_kong_get_next_upstream_mask(r, u->conf->next_upstream) & ft_type) != ft_type)
+#else
         || ((u->conf->next_upstream & ft_type) != ft_type)
+#endif
+
         || (u->request_sent && r->request_body_no_buffering)
         || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
     {
