Repository navigation
bugfix: balancer keepalive connections were never reused with proxy_bind - #2533
Merged
zhuizhuhaomeng merged 1 commit intoOct 19, 2026
Merged
Conversation
…ind. When proxy_bind sets the local address and balancer_by_lua* enables keepalive without calling balancer.bind_to_local_addr(), pc->local holds the proxy_bind address while bp->local is NULL. free_peer hashed the saved connection with bp->local, but get_cached_item looks it up with pc->local, so the lookup never matched: every connection was saved, never reused, and closed when it idled out. Hash with pc->local, which is the address the connection was bound to and the one stored in item->local_sockaddr. Since nginx 1.29.7 the "keepalive" directive is enabled by default and its cache takes the connections before the Lua pool, so the test turns it off with "keepalive 0" on those versions.
zhuizhuhaomeng
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
proxy_bindset andbalancer.enable_keepalive()used withoutbalancer.bind_to_local_addr(), connections are saved to the Lua keepalive pool but never reused.Since 6738c3a the pool key includes the local address.
free_peer()hashed it frombp->local(NULL here), whileget_cached_item()usespc->local(theproxy_bindaddress), so the lookup never matched.The fix hashes with
pc->local, which is whatconnect()bound and what the item stores. Withoutproxy_bindor withbind_to_local_addr(),pc->localequalsbp->local, so those cases behave as before.I also added a test that alternates two
proxy_bindaddresses and expects each to reuse its own connection. If fails before the fix, passes with the fix.I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.