-
-
Notifications
You must be signed in to change notification settings - Fork 478
fix(beacon-node): cleanly exit process on graceful shutdown #5330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dfcef4d
198bbf4
51d30ed
9cf34fc
ce69277
fa796ad
c467ef6
b01f7eb
c208195
75566a0
c87290b
a770fc1
32983cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import {Registry} from "prom-client"; | |
| import {PeerId} from "@libp2p/interface-peer-id"; | ||
| import {BeaconConfig} from "@lodestar/config"; | ||
| import {phase0} from "@lodestar/types"; | ||
| import {sleep} from "@lodestar/utils"; | ||
| import {LoggerNode} from "@lodestar/logger/node"; | ||
| import {Api, ServerApi} from "@lodestar/api"; | ||
| import {BeaconStateAllForks} from "@lodestar/state-transition"; | ||
|
|
@@ -74,6 +75,12 @@ enum LoggerModule { | |
| sync = "sync", | ||
| } | ||
|
|
||
| /** | ||
| * Short delay before closing db to give async operations sufficient time to complete | ||
| * and prevent "Database is not open" errors when shutting down beacon node. | ||
| */ | ||
| const DELAY_BEFORE_CLOSING_DB_MS = 500; | ||
|
|
||
| /** | ||
| * The main Beacon Node class. Contains various components for getting and processing data from the | ||
| * Ethereum Consensus ecosystem as well as systems for getting beacon node metadata. | ||
|
|
@@ -316,11 +323,11 @@ export class BeaconNode { | |
| if (this.metricsServer) await this.metricsServer.stop(); | ||
| if (this.monitoring) this.monitoring.stop(); | ||
| if (this.restApi) await this.restApi.close(); | ||
|
|
||
| await this.chain.persistToDisk(); | ||
| await this.chain.close(); | ||
| await this.db.stop(); | ||
| if (this.controller) this.controller.abort(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abort must be called before closing db
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, it is best to abort as late as possible in shutdown sequence. This ensures all intervals/timeouts are cleared first and then all remaining pending operations are aborted. Prevents edge case where abort is done and interval schedules another operation which would be stuck pending and delay shutdown. |
||
| await sleep(DELAY_BEFORE_CLOSING_DB_MS); | ||
| await this.db.stop(); | ||
| this.status = BeaconNodeStatus.closed; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export * from "./fnQueue.js"; | ||
| export * from "./itemQueue.js"; | ||
| export * from "./options.js"; | ||
| export {QueueError, QueueErrorCode} from "./errors.js"; | ||
| export {QueueError, QueueErrorCode, isQueueErrorAborted} from "./errors.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per documentation, "Database is not open" only happens if close is already called and some async operation still tries to execute db queries. If db query is already executed before, the database will wait for any pending operations to finish before closing.