GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Wrap ECONNREFUSED in PortUnreachableException for UDP (#16131) by normanmaurer · Pull Request #16150 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Jan 17, 2026

Copy link
Copy Markdown
Member

Motivation:

Currently, KQueueDatagramChannel handles ECONNREFUSED inconsistently
depending on how data is sent:

  • sendToAddress() (Unconnected): Correctly wraps errors in
    PortUnreachableException.
  • writeAddress() (Connected): Returns raw ECONNREFUSED, causing an
    inconsistency with NIO behaviour.

In NIO, the exception is thrown from the write path:

 java.net.PortUnreachableException
    at java.base/sun.nio.ch.DatagramDispatcher.write0(Native Method)
    at java.base/sun.nio.ch.DatagramDispatcher.write(DatagramDispatcher.java:51)
    at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:137)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:81)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:58)
    at java.base/sun.nio.ch.DatagramChannelImpl.write(DatagramChannelImpl.java:1160)
    at io.netty.channel.socket.nio.NioDatagramChannel.doWriteMessage(NioDatagramChannel.java:309)

Modifications:

  • Introduced translateForConnected() to handle error mapping
    specifically for the connected state.
  • Updated doWriteMessage() to apply this translation when the channel
    is connected (remoteAddress == null) and writeAddress() fails with
    ECONNREFUSED.

Result:

Improved behavioural parity between KQueue and NIO transports. Users
will now receive a consistent PortUnreachableException regardless of
the send path used.


Co-authored-by: Norman Maurer [email protected]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
violetagg and others added 3 commits January 17, 2026 14:10
@violetagg @normanmaurer
Wrap ECONNREFUSED in PortUnreachableException for UDP (#16131)
67a76b2
Motivation:

Currently, `KQueueDatagramChannel` handles `ECONNREFUSED` inconsistently
depending on how data is sent:
- `sendToAddress()` (Unconnected): Correctly wraps errors in
`PortUnreachableException`.
- `writeAddress()` (Connected): Returns raw `ECONNREFUSED`, causing an
inconsistency with `NIO` behaviour.

In `NIO`, the exception is thrown from the write path:

```
 java.net.PortUnreachableException
    at java.base/sun.nio.ch.DatagramDispatcher.write0(Native Method)
    at java.base/sun.nio.ch.DatagramDispatcher.write(DatagramDispatcher.java:51)
    at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:137)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:81)
    at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:58)
    at java.base/sun.nio.ch.DatagramChannelImpl.write(DatagramChannelImpl.java:1160)
    at io.netty.channel.socket.nio.NioDatagramChannel.doWriteMessage(NioDatagramChannel.java:309)
```

Modifications:

- Introduced `translateForConnected()` to handle error mapping
specifically for the connected state.
- Updated `doWriteMessage()` to apply this translation when the channel
is connected (`remoteAddress == null`) and `writeAddress()` fails with
`ECONNREFUSED`.

Result:

Improved behavioural parity between `KQueue` and `NIO` transports. Users
will now receive a consistent `PortUnreachableException` regardless of
the send path used.

---------

Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer
Fix compilation error
cd332be
@normanmaurer
Fix compilation error
9431f53
@normanmaurer normanmaurer added this to the 4.1.131.Final milestone Jan 18, 2026
@normanmaurer
normanmaurer merged commit 496f55c into 4.1 Jan 18, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer deleted the data41 branch January 18, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.131.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@normanmaurer @violetagg
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.