Skip to content

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

Merged
kuny0707 merged 2 commits into
tronprotocol:developfrom
0xbigapple:fix/threadpool-submit-issue
May 8, 2026
Merged

fix(net): fix RejectedExecutionException during shutdown trxHandlePool#6692
kuny0707 merged 2 commits into
tronprotocol:developfrom
0xbigapple:fix/threadpool-submit-issue

Conversation

@0xbigapple
Copy link
Copy Markdown
Collaborator

What does this PR do?

Fix RejectedExecutionException during node shutdown in TransactionsMsgHandler.

  • Correct shutdown order (core): stop producer smartContractExecutor first, then consumer trxHandlePool, guaranteeing trxHandlePool is alive while the scheduler runs.
  • isClosed flag: early exit in processMessage() at entry and during iteration. Covers in-flight messages in the narrow window between PeerManager.close() and handler close.
  • RejectedExecutionException catch: handles TOCTOU race between isClosed check and submit().
  • Queue cleanup: clear smartContractQueue and queue after both pools terminate.

Why are these changes required?

The original close() shut down the consumer pool (trxHandlePool) before the producer scheduler (smartContractExecutor). During this window, handleSmartContract() was still draining smartContractQueue and calling submit(trxHandlePool, ...) on an already-terminated pool, throwing RejectedExecutionException and polluting shutdown logs.

Thread model

P2P threads ── processMessage() ──┬── submit(trxHandlePool)        [normal txs]
                                  └── smartContractQueue.offer()    [smart contracts]

smartContractExecutor (single-thread, 20ms delay)
    └── handleSmartContract() → take() → submit(trxHandlePool)

close()
    1. isClosed = true
    2. shutdownAndAwaitTermination(smartContractExecutor)  ← producer first
    3. shutdownAndAwaitTermination(trxHandlePool)          ← consumer second
    4. smartContractQueue.clear(); queue.clear()

This PR has been tested by:

  • Unit Tests
  • Manual Testing: Restart the node repeatedly, verified via log grep:
    • No RejectedExecutionException
    • Correct shutdown order (contract-msg-handler shutdown done before trx-msg-handler shutdown done)

Follow up

N/A

Extra details

@github-actions github-actions Bot requested review from 317787106 and xxo1shine April 17, 2026 04:22
@halibobo1205 halibobo1205 added the topic:net p2p net work, synchronization label Apr 18, 2026
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone Apr 18, 2026
Copy link
Copy Markdown
Collaborator

@halibobo1205 halibobo1205 left a comment

Choose a reason for hiding this comment

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

LGTM

@kuny0707 kuny0707 merged commit 107490c into tronprotocol:develop May 8, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this to Done in java-tron May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:net p2p net work, synchronization

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants