Skip to content

fix(eth): reorder ethereum shutdown sequence#2277

Open
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-eth-stop
Open

fix(eth): reorder ethereum shutdown sequence#2277
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-eth-stop

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

@gzliudan gzliudan commented Apr 6, 2026

Proposed changes

Close the ethereum shutdown channel before closing the chain database so bloom handler goroutines can exit first. Add stop-step logs around the shutdown path to pinpoint hangs during node exit.

some log messages about abnormal exit:

INFO [04-06|09:42:40.902] Got interrupt, shutting down...
INFO [04-06|09:42:40.911] HTTP server stopped                      endpoint=[::]:8646
INFO [04-06|09:42:40.914] HTTP server stopped                      endpoint=[::]:9646
INFO [04-06|09:42:40.919] IPC endpoint closed                      url=/home/me/xdc_chain/mainnet_2/XDC.ipc
INFO [04-06|09:42:40.922] Blockchain manager stopped
INFO [04-06|09:42:40.922] Stopping Ethereum protocol
WARN [04-06|09:42:40.926] BFT Loop Close
INFO [04-06|09:42:40.940] Ethereum protocol stopped
INFO [04-06|09:42:40.940] Transaction pool stopped

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Close the ethereum shutdown channel before closing the chain database so bloom handler goroutines can exit first.
Add stop-step logs around the shutdown path to pinpoint hangs during node exit.
Copilot AI review requested due to automatic review settings April 6, 2026 04:33
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 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: cde8a249-dfce-46ac-b380-6cea6702a04c

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

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

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

Reorders parts of the Ethereum service shutdown sequence to signal bloom-bits handler goroutines earlier (before closing the chain DB) and adds additional stop-step logging to help diagnose node exit hangs.

Changes:

  • Move close(e.shutdownChan) to occur before e.chainDb.Close().
  • Add start/stop log lines around each shutdown step (bloom indexer, blockchain, protocol manager, txpool, miner, event mux, DB).

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

Comment on lines +583 to +585
log.Info("Stopping Ethereum bloomIndexer start")
e.bloomIndexer.Close()
log.Info("Ethereum bloomIndexer stopped")
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

e.bloomIndexer.Close() returns an error, but it’s currently ignored while logs unconditionally report it as “stopped”. Since Ethereum.Stop() has an error return, consider capturing/propagating the close error (or at least logging it) so shutdown failures aren’t silently missed.

Copilot uses AI. Check for mistakes.
Comment on lines +599 to 612
log.Info("Stopping Ethereum shutdownChan start")
close(e.shutdownChan)
log.Info("Ethereum shutdownChan stopped")

log.Info("Stopping Ethereum miner start")
e.miner.Stop()
log.Info("Ethereum miner stopped")

log.Info("Stopping Ethereum eventMux start")
e.eventMux.Stop()
log.Info("Ethereum eventMux stopped")

log.Info("Stopping Ethereum chainDb start")
e.chainDb.Close()
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Closing shutdownChan only signals the bloom service goroutines to exit; it doesn’t ensure they’ve actually stopped before chainDb.Close() runs. In startBloomHandlers the goroutine may still be mid-task (inner for over sections) and continue reading from eth.chainDb. If the intent is to let bloom handlers exit before closing the DB (and avoid shutdown hangs), consider tracking these goroutines with a sync.WaitGroup and waiting after close(e.shutdownChan) (and/or checking shutdownChan inside the per-section loop) prior to closing chainDb.

Copilot uses AI. Check for mistakes.
log.Info("Ethereum eventMux stopped")

log.Info("Stopping Ethereum chainDb start")
e.chainDb.Close()
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

e.chainDb.Close() (io.Closer) can return an error, but it’s ignored and the subsequent log line reports the DB as “stopped” regardless. Consider handling/logging the returned error and (optionally) returning it from Ethereum.Stop() so callers can detect shutdown failures.

Suggested change
e.chainDb.Close()
if err := e.chainDb.Close(); err != nil {
log.Error("Failed to stop Ethereum chainDb", "err", err)
return err
}

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.

3 participants