Skip to content

Auto-port 5.0: SingleThreadEventExecutor: document Throwable safety contract on run() - #16907

Merged
chrisvest merged 1 commit into
5.0from
auto-port-pr-16814-to-5.0
Jun 4, 2026
Merged

chrisvest merged 1 commit into
5.0from
auto-port-pr-16814-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #16814 to 5.0
Cherry-picked commit: 344d6db


Motivation:

Subclasses of SingleThreadEventExecutor can silently take down the event-loop thread — and with it every Channel registered to that loop — if their run() implementation lets a Throwable escape from a task invocation. The default helpers (runAllTasks*, safeExecute) catch Throwable correctly, but the abstract run() contract gives no hint that this is a hard requirement; the existing one-line javadoc just says "Run the tasks in the taskQueue". Subclassers writing bespoke task loops on top of pollTask/takeTask have no guidance — see #16102 for the full report.

Modification:

Expand the javadoc on SingleThreadEventExecutor#run() to spell out:

  • run() must keep going until confirmShutdown() returns true;
  • an uncaught Throwable terminates the event-loop thread and silently breaks every Channel registered to it;
  • runAllTasks(), runAllTasks(long), and safeExecute(Runnable) already handle Throwable, so prefer them;
  • custom loops built on pollTask()/takeTask() must wrap each task invocation themselves.

No code change.

Result:

Implementers of SingleThreadEventExecutor see the safety contract on the method they are required to override, rather than discovering the failure mode in production.

Refs #16102. The optional "Defensive Mechanism" piece (enforce an UncaughtExceptionHandler on event-loop threads) from the original issue is intentionally out of scope here — happy to do that as a follow-up if maintainers want it.

#16814)

Motivation:

Subclasses of `SingleThreadEventExecutor` can silently take down the
event-loop thread — and with it every `Channel` registered to that loop
— if their `run()` implementation lets a `Throwable` escape from a task
invocation. The default helpers (`runAllTasks*`, `safeExecute`) catch
`Throwable` correctly, but the abstract `run()` contract gives no hint
that this is a hard requirement; the existing one-line javadoc just says
"Run the tasks in the taskQueue". Subclassers writing bespoke task loops
on top of `pollTask`/`takeTask` have no guidance — see #16102 for the
full report.

Modification:

Expand the javadoc on `SingleThreadEventExecutor#run()` to spell out:

- `run()` must keep going until `confirmShutdown()` returns `true`;
- an uncaught `Throwable` terminates the event-loop thread and silently
breaks every `Channel` registered to it;
- `runAllTasks()`, `runAllTasks(long)`, and `safeExecute(Runnable)`
already handle `Throwable`, so prefer them;
- custom loops built on `pollTask()`/`takeTask()` must wrap each task
invocation themselves.

No code change.

Result:

Implementers of `SingleThreadEventExecutor` see the safety contract on
the method they are required to override, rather than discovering the
failure mode in production.

Refs #16102. The optional "Defensive Mechanism" piece (enforce an
`UncaughtExceptionHandler` on event-loop threads) from the original
issue is intentionally out of scope here — happy to do that as a
follow-up if maintainers want it.

---------

Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit 344d6db)
@chrisvest chrisvest added this to the 5.0.0.Final milestone Jun 4, 2026
@chrisvest
chrisvest merged commit 59b43b3 into 5.0 Jun 4, 2026
12 of 13 checks passed
@chrisvest
chrisvest deleted the auto-port-pr-16814-to-5.0 branch June 4, 2026 22:14
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
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.

3 participants