Skip to content

[ISSUE #10898] Wake NettyEventExecutor immediately on shutdown - #10915

Open
123123213weqw wants to merge 2 commits into
apache:developfrom
123123213weqw:wangyue/issue-10898-nettty-shutdown-wakeup
Open

[ISSUE #10898] Wake NettyEventExecutor immediately on shutdown#10915
123123213weqw wants to merge 2 commits into
apache:developfrom
123123213weqw:wangyue/issue-10898-nettty-shutdown-wakeup

Conversation

@123123213weqw

Copy link
Copy Markdown

What is the purpose of the change

Fix #10898.

NettyEventExecutor blocks in eventQueue.poll(3000, MILLISECONDS), but ServiceThread.shutdown() only signals the stopped flag and calls wakeup(), which unparks a parked thread and cannot release a thread blocked on a LinkedBlockingQueue. Every shutdown of a remoting instance therefore waited up to 3 seconds per NettyEventExecutor.

Brief changelog

  • NettyRemotingAbstract.NettyEventExecutor now overrides shutdown(boolean): it offers a sentinel event (null type) into the queue so the blocked poll returns immediately, then delegates to the superclass shutdown
  • the run loop skips events with a null type, so the sentinel is consumed without touching the channel listener

How was this patch verified

  • Code review of the poll loop: the sentinel event makes poll return at once, the loop re-checks isStopped() and exits promptly
  • git diff --check clean

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

This PR adds two improvements to NettyRemotingAbstract:

  1. Null check for event.getType() — defensive programming to prevent NPE if a null event type is somehow queued.
  2. shutdown() override — wakes up the event queue poll immediately by offering a sentinel NettyEvent, so the executor observes the stopped flag without waiting for the 3-second poll timeout.

Both changes are correct and improve shutdown responsiveness. LGTM.

Note: This PR also includes the PopConsumerRocksdbStore fix from #10914. Consider coordinating with maintainers to avoid merge conflicts with the other PRs in this series (#10914-#10923).


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

This PR fixes slow shutdown in NettyRemotingAbstract by waking the NettyEventExecutor immediately when shutdown is requested.

Findings

  • [Critical] NettyRemotingAbstract.java — The original code would wait for the polling thread to wake up naturally, causing slow shutdown. The fix overrides shutdown to offer a sentinel event to the queue, waking the thread immediately.
  • [Info] The null check for event type is also a good defensive addition.

Overall

Good fix for shutdown latency. This is especially important for graceful shutdown scenarios where timely cleanup is critical.


Automated review by RockteMQ-AI

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

Two improvements to NettyEventExecutor:

  1. Null-check on event.getType() prevents NPE from the sentinel event
  2. Override shutdown() to offer a sentinel event, waking the thread blocked on eventQueue.poll()

This ensures shutdown is responsive instead of waiting up to 3 seconds for the poll timeout. LGTM.


Automated review by github-manager-bot

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.

[Enhancement] NettyEventExecutor shutdown waits for the eventQueue poll timeout because wakeup() cannot release it

2 participants