Skip to content

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

Closed
0xbigapple wants to merge 1 commit intotronprotocol:developfrom
0xbigapple:fix/threadpool-submit-issue
Closed

fix(net): fix RejectedExecutionException during shutdown trxHandlePool#6691
0xbigapple wants to merge 1 commit intotronprotocol: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

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.

1 participant