Skip to content

fix(net): fix RejectedExecutionException during shutdown trxHandlePool#8

Open
0xbigapple wants to merge 2 commits intodevelopfrom
fix/threadpool-submit-issue
Open

fix(net): fix RejectedExecutionException during shutdown trxHandlePool#8
0xbigapple wants to merge 2 commits intodevelopfrom
fix/threadpool-submit-issue

Conversation

@0xbigapple
Copy link
Copy Markdown
Owner

@0xbigapple 0xbigapple commented Mar 30, 2026

What does this PR do?
fix RejectedExecutionException during shutdown trxHandlePool

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details


Summary by cubic

Fixes RejectedExecutionException during shutdown by gating task submissions in TransactionsMsgHandler and shutting down the scheduler before the worker pool. Ensures clean shutdown without exceptions after close, dropping only queued smart-contract tasks.

  • Bug Fixes
    • Added volatile isClosed flag to block new tasks and guard iteration.
    • Changed shutdown order: close smartContractExecutor first, then trxHandlePool; drop pending smartContractQueue items.
    • Early return in processMessage when closed; re-check during batch processing.
    • Catch RejectedExecutionException on submit to trxHandlePool and stop submitting.
    • Added test testProcessMessageAfterClose to ensure messages are ignored after close().

Written for commit c3e2c56. Summary will update on new commits.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b53b593b-1186-4118-91ee-625bc640b82d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/threadpool-submit-issue

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Copy link
Copy Markdown

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

Fixes shutdown-time RejectedExecutionException in TransactionsMsgHandler by preventing new task submissions after close and changing executor shutdown ordering to stop the scheduler before the worker pool.

Changes:

  • Add an isClosed flag and guard processMessage/iteration to stop submitting work during shutdown.
  • Change shutdown order to terminate smartContractExecutor before trxHandlePool, and catch RejectedExecutionException on submit.
  • Add a unit test to ensure processMessage() does not throw after close().

Reviewed changes

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

File Description
framework/src/main/java/org/tron/core/net/messagehandler/TransactionsMsgHandler.java Adds close-gating and adjusts executor shutdown order to avoid rejected submissions during shutdown.
framework/src/test/java/org/tron/core/net/messagehandler/TransactionsMsgHandlerTest.java Adds a regression test ensuring processMessage is safe after handler close.

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

Copy link
Copy Markdown

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

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


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

Comment on lines +68 to +73
isClosed = true;
// Shutdown the producer (scheduler) first.
// Pending tasks in smartContractQueue will be discarded.
ExecutorServiceManager.shutdownAndAwaitTermination(smartContractExecutor, smartEsName);
// Then shutdown the consumer (worker pool) to finish tasks already submitted to trxHandlePool.
ExecutorServiceManager.shutdownAndAwaitTermination(trxHandlePool, trxEsName);
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

close() comment says pending smartContractQueue tasks will be discarded, but the method only stops the scheduler and shuts down the pools; it never clears/drains smartContractQueue. If this handler remains referenced (it’s a Spring @Component), queued TrxEvents (including PeerConnection references) will be retained until JVM exit. Consider clearing/draining the queue after the scheduler has fully terminated (after shutdownAndAwaitTermination(smartContractExecutor, ...)) to make the discard behavior real and release references.

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +101
// Re-check isClosed status during iteration to handle concurrent shutdown
if (isClosed) {
logger.warn("TransactionsMsgHandler is closed during processing, stop submit.");
break;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

When isClosed flips to true (or trxHandlePool starts rejecting), this loop breaks early, but the earlier loop has already removed all tx items from peer.getAdvInvRequest(). That can leave some transactions neither queued nor requested anymore. To avoid silently dropping txs, consider removing items from advInvRequest only after a tx is successfully enqueued/submitted (or stop removing once shutdown is detected).

Copilot uses AI. Check for mistakes.
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