Skip to content

Share DNS resolver group across connections. - #758

Closed
mdedetrich wants to merge 1 commit into
pgjdbc:mainfrom
mdedetrich:fix-dns-resolver-leak
Closed

mdedetrich wants to merge 1 commit into
pgjdbc:mainfrom
mdedetrich:fix-dns-resolver-leak

Conversation

@mdedetrich

Copy link
Copy Markdown

Resolves #756.

Since #724, ReactorNettyClient.connect(…) calls TcpClient.resolver(Consumer) per connection, which creates a new DnsAddressResolverGroup each time. Closing the connection doesn't close the group, so every connection retains a DNS UDP socket.

This caches one round-robin resolver group per LoopResources/preferNative, mirroring Reactor Netty's own resolver cache, so all connections share it.

TcpClient setup is extracted into createTcpClient(…) so tests can assert that clients share the resolver; they fail against the previous code. The connect(…) diff is mostly that move.

Verified with the reproduction from the issue (30 connect/close cycles by hostname): retained UDP sockets grow 10/20/30 before the change and plateau at 16 (one per event loop) after.

New Public APIs

None.

ReactorNettyClient.connect(…) configured a new TcpClient per connection via resolver(Consumer), which creates a new DnsAddressResolverGroup on every call. Each group allocates a DNS resolver with its own UDP socket per event loop, and closing the connection never closes it, retaining one socket per connection.

Cache one round-robin resolver group per LoopResources and preferNative setting, mirroring Reactor Netty's own resolver cache, so all connections share it.

Extract TcpClient setup into createTcpClient(…) to verify resolver sharing.
@mp911de

mp911de commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Initially, we had 33287ab as motivation to move off our own resolver. Now, after applying a series of LLM-assisted pull requests that changed the general shape of this project to a worse state I am not convinced that throwing code at a problem until it seems to fix something previously unwanted while it is introducing a series of other problems, such as an anonymously keyed list holding on to static resources that never get cleaned up.

In contrast, our previous balancer group might had suffered from other aspects yet it had well-defined retention model that was easier to discover. Therefore, we don't want to merge this change because it leads to harder to understand/maintain code.

@mp911de mp911de closed this Oct 26, 2026
@mp911de mp911de added the status: declined A suggestion or change that we don't feel we should currently apply label Oct 26, 2026
@mdedetrich

mdedetrich commented Oct 26, 2026 •

Copy link
Copy Markdown
Author

Initially, we had 33287ab as motivation to move off our own resolver. Now, after applying a series of LLM-assisted pull requests that changed the general shape of this project to a worse state I am not convinced that throwing code at a problem until it seems to fix something previously unwanted while it is introducing a series of other problems, such as an anonymously keyed list holding on to static resources that never get cleaned up.

In contrast, our previous balancer group might had suffered from other aspects yet it had well-defined retention model that was easier to discover. Therefore, we don't want to merge this change because it leads to harder to understand/maintain code.

No worries, just wanted to help out since we had to revert to 1.1.2-RELEASE because of this leak (its unusable for us).

It is a bit surprising that the original LLM-assisted PR's (i.e. 33287ab) didn't pick regression that it ended up causing (this hasn't been my experience).

@mdedetrich
mdedetrich deleted the fix-dns-resolver-leak branch October 26, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS UDP socket retention regression in 1.1.3.RELEASE (minimal reproduction and 1.1.2 comparison)

2 participants