Skip to content

Comments

Call Bootstrap.connect() with resolved InetSocketAddress#137

Merged
kevinherron merged 2 commits intomasterfrom
copilot/fix-netty-transport-issue
Dec 9, 2025
Merged

Call Bootstrap.connect() with resolved InetSocketAddress#137
kevinherron merged 2 commits intomasterfrom
copilot/fix-netty-transport-issue

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

Hostname resolution was occurring on Netty event loop threads instead of the calling thread. This mirrors the fix in eclipse-milo/milo#1668.

Changes

  • NettyTcpClientTransport: Construct InetSocketAddress before passing to Bootstrap.connect()
  • NettyRtuClientTransport: Construct InetSocketAddress before passing to Bootstrap.connect()

Technical Details

Calling Bootstrap.connect(hostname, port) creates an unresolved InetSocketAddress that Netty resolves later on its event loop. Passing a pre-constructed InetSocketAddress(hostname, port) forces immediate DNS resolution on the calling thread.

// Before
bootstrap.connect(config.hostname(), config.port())

// After  
bootstrap.connect(new InetSocketAddress(config.hostname(), config.port()))

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/modbus/.codeql-scratch/dbs/java/working/files-to-index11882398739134291682.list --sourceArchiveDir=/home/REDACTED/work/modbus/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/modbus/.codeql-scratch/dbs/java/trap/java (dns block)
  • https://api.github.com/repos/eclipse-milo/milo/pulls/1668
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

The fix done in this PR to the Milo repository: eclipse-milo/milo#1668

fixes an issues that also likely needs to be fixed here. Find out of the Netty transport connects using the same API that results in an unresolved InetSocketAddress and if so make the same fix here.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: kevinherron <340273+kevinherron@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unresolved InetSocketAddress issue in Netty transport Call Bootstrap.connect() with resolved InetSocketAddress Dec 9, 2025
Copilot AI requested a review from kevinherron December 9, 2025 00:26
@kevinherron kevinherron marked this pull request as ready for review December 9, 2025 00:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a performance issue where hostname resolution was occurring on Netty event loop threads instead of the calling thread. This mirrors the fix from eclipse-milo/milo#1668 and ensures DNS resolution doesn't block event loop threads that should be reserved for I/O operations.

Key Changes:

  • Modified both Netty client transport implementations to pre-construct InetSocketAddress objects before passing them to Bootstrap.connect()
  • Added java.net.InetSocketAddress import to both affected files

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
modbus-tcp/src/main/java/com/digitalpetri/modbus/tcp/client/NettyTcpClientTransport.java Updated TCP client transport to resolve hostnames on the calling thread by pre-constructing InetSocketAddress
modbus-tcp/src/main/java/com/digitalpetri/modbus/tcp/client/NettyRtuClientTransport.java Updated RTU/TCP client transport to resolve hostnames on the calling thread by pre-constructing InetSocketAddress

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kevinherron kevinherron merged commit 5beb2c3 into master Dec 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants