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 — Prevent ManualEventLoop to block on a racy task submission by franz1981 · Pull Request #15937 · netty/netty

Conversation

@franz1981

@franz1981 franz1981 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Motivation:

ManualEventLoop can be blocked forever if not aware of task submissions before getting asleep

Modification:

Expands the ManualIoEventLoop API to make it aware of additional non-blocking conditions and correctly enqueue an empty task while shutting down to prevent a racy sleep to happen. Additionally, fix the blocking deadline math computation taking in account negativeness and whilst no deadline is set: for the latter, change the default previous deadline value of EpollIoHandler into NONE, to save performing timed wait, if no deadline is specified

Result:

ManualIoEventLoop correctly make progress if there's work to perform and terminate, while shutdown

Fixes #15922

Sorry, something went wrong.

Uh oh!

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

He-Pin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@franz1981
franz1981 requested review from normanmaurer and yawkat November 27, 2025 05:31
franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java Resolved

Uh oh!

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

franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java Resolved

Uh oh!

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

@franz1981
franz1981 force-pushed the 4.2_epoll_manual branch from e112199 to 8901b4f Compare November 27, 2025 05:47
franz1981
franz1981 commented Nov 27, 2025
View reviewed changes
Comment thread transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java Resolved

Uh oh!

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

@franz1981
franz1981 force-pushed the 4.2_epoll_manual branch 2 times, most recently from ef9e228 to c96a86c Compare November 27, 2025 06:03
He-Pin
He-Pin reviewed Nov 27, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

@franz1981
Prevent ManualEventLoop to block on a racy task submission
dcab167
Motivation:

ManualEventLoop can be blocked forever if not aware of task submissions before getting asleep

Modification:

Expands the ManualIoEventLoop API to make it aware of additional non-blocking conditions and
correctly enqueue an empty task while shutting down to prevent a racy sleep to happen.
Additionally, fix the blocking deadline math computation taking in account negativeness and
whilst no deadline is set: for the latter, change the default previous deadline value
of EpollIoHandler into NONE, to save performing timed wait, if no deadline is specified

Result:

ManualIoEventLoop correctly make progress if there's work to perform and terminate, while shutdown
@franz1981
franz1981 force-pushed the 4.2_epoll_manual branch from c96a86c to dcab167 Compare November 27, 2025 06:05
@franz1981
address comment
3c31887
normanmaurer
normanmaurer requested changes Nov 27, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

Comment thread transport/src/main/java/io/netty/channel/ManualIoEventLoop.java Resolved

Uh oh!

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

Comment thread transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java Resolved

Uh oh!

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

Comment thread transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java Resolved

Uh oh!

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

Comment thread transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java Resolved

Uh oh!

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

franz1981 added 2 commits November 27, 2025 17:11
@franz1981
final all the things
3a7429c
@franz1981
private tests
83f6367
@franz1981

franz1981 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor Author

PTAL @normanmaurer

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981
fix codestyle
09d179d
@franz1981

franz1981 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor Author

@normanmaurer
I think I have to tell ravapi to not be bothered by the final :"(

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981
Fix Long.MAX_VALUE delays and wrapping
85beafd
@franz1981

franz1981 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

@normanmaurer @chrisvest I can see how NIO is much worse than EPOLL, perf wise: is not only due to EPOLLET but the wakeup mechanism of NIO doesn't track the event loop state, but just try to save too many in-flight wakeup(s).
Usually this is not a problem because inEventLoop prevent channel handling code to bother the selector, but with https://github.com/franz1981/Netty-VirtualThread-Scheduler it's a whole different story: virtual threads which are handled on the same carrier of the event loop could appear as alien threads and always trigger wakeup(s) (at least one, let's say!) - which is pretty bad, since they are physically running on the same platform thread (the carrier).

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981
Fix revapi
e9a53d7
@franz1981

franz1981 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

@normanmaurer I have fixed a NIO error which prevented to use select(0) when there are no scheduled tasks.
I'm now checking io_uring as well ^^

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981
Fix revapi
bf9d0b5
@franz1981

franz1981 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

Fighting revapi 😢

All reactions

Sorry, something went wrong.

Uh oh!

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

franz1981
franz1981 commented Nov 28, 2025
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/nio/NioIoHandler.java
assert selectDeadLineNanos != Long.MAX_VALUE;
long nanosBeforeDeadline = selectDeadLineNanos - currentTimeNanos;
// Prevent overflow when adding the rounding bias:
// if we don't do this, it would appear as the deadline is already reached!

@franz1981 franz1981 Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@normanmaurer this is the actual fix: i was observing a select without any timeout to still call selectNow instead - which is not right

Sorry, something went wrong.

Uh oh!

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

All reactions
@franz1981 franz1981 mentioned this pull request Nov 28, 2025
io.netty.channel.epoll.EpollEventLoopTest.testSubmittingTaskWakesUpSuspendedExecutor failure #15648
Open
@franz1981

franz1981 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

The failure is on a flaky test @normanmaurer PTAL

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer requested review from He-Pin and chrisvest and removed request for He-Pin December 3, 2025 18:12
@normanmaurer

normanmaurer commented Dec 3, 2025

Copy link
Copy Markdown
Member

@chrisvest PTAL as well

All reactions

Sorry, something went wrong.

Uh oh!

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

chrisvest
chrisvest approved these changes Dec 4, 2025
View reviewed changes

@chrisvest chrisvest left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This was challenging to review, but it looks good.

Sorry, something went wrong.

Uh oh!

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

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@franz1981

franz1981 commented Dec 5, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @chrisvest and sorry; I hope I didn't made it too complex for no reasons 🙏

All reactions

Sorry, something went wrong.

Uh oh!

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

normanmaurer
normanmaurer approved these changes Dec 9, 2025
View reviewed changes
@normanmaurer
normanmaurer merged commit 35f6ad1 into netty:4.2 Dec 9, 2025
@normanmaurer

normanmaurer commented Dec 9, 2025

Copy link
Copy Markdown
Member

@franz1981 thanks!

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@normanmaurer normanmaurer added this to the 4.2.8.Final milestone Dec 9, 2025
normanmaurer pushed a commit that referenced this pull request Dec 9, 2025
@franz1981 @normanmaurer
Prevent ManualEventLoop to block on a racy task submission (#15937)
1fb0010
Motivation:

ManualEventLoop can be blocked forever if not aware of task submissions
before getting asleep

Modification:

Expands the ManualIoEventLoop API to make it aware of additional
non-blocking conditions and correctly enqueue an empty task while
shutting down to prevent a racy sleep to happen. Additionally, fix the
blocking deadline math computation taking in account negativeness and
whilst no deadline is set: for the latter, change the default previous
deadline value of EpollIoHandler into NONE, to save performing timed
wait, if no deadline is specified

Result:

ManualIoEventLoop correctly make progress if there's work to perform and
terminate, while shutdown

Fixes #15922
normanmaurer added a commit that referenced this pull request Dec 9, 2025
@normanmaurer @franz1981
Prevent ManualEventLoop to block on a racy task submission (#15937) (#…
e39f432
…16001)

Motivation:

ManualEventLoop can be blocked forever if not aware of task submissions
before getting asleep

Modification:

Expands the ManualIoEventLoop API to make it aware of additional
non-blocking conditions and correctly enqueue an empty task while
shutting down to prevent a racy sleep to happen. Additionally, fix the
blocking deadline math computation taking in account negativeness and
whilst no deadline is set: for the latter, change the default previous
deadline value of EpollIoHandler into NONE, to save performing timed
wait, if no deadline is specified

Result:

ManualIoEventLoop correctly make progress if there's work to perform and
terminate, while shutdown

Fixes #15922

Co-authored-by: Francesco Nigro <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
suspend race fix #17588
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
child5 #17695
Closed
@LivingLikeKrillin LivingLikeKrillin mentioned this pull request Oct 17, 2026
Lost wakeup in LoomCarrierGroup can delay continuations until blockTime on native epoll micronaut-projects/micronaut-core#13993
Open
This was referenced Oct 20, 2026
fix iouring zerocopy iov overwrite #17936
Closed
crisp nova cceda091 #18109
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
@normanmaurer normanmaurer normanmaurer approved these changes
@yawkat yawkat Awaiting requested review from yawkat
+1 more reviewer
@He-Pin He-Pin He-Pin left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.8.Final

Development

Successfully merging this pull request may close these issues.

Racy wakeup attempts prevent manual io event loop to shutdown with EPOLL

Uh oh!

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

4 participants

@franz1981 @normanmaurer @chrisvest @He-Pin
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.