-
Notifications
You must be signed in to change notification settings - Fork 120
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
Implement graceful shutdown in Fluffy #2645
Changes from 3 commits
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 |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
import | ||
results, | ||
chronos, | ||
metrics/chronos_httpserver, | ||
json_rpc/rpcserver, | ||
eth/p2p/discoveryv5/protocol, | ||
beacon_chain/spec/forks, | ||
./network_metadata, | ||
|
@@ -24,6 +26,11 @@ export | |
beacon_light_client, history_network, state_network, portal_protocol_config, forks | ||
|
||
type | ||
PortalNodeState* = enum | ||
Starting | ||
Running | ||
Stopping | ||
|
||
PortalNodeConfig* = object | ||
accumulatorFile*: Opt[string] | ||
disableStateRootValidation*: bool | ||
|
@@ -33,6 +40,7 @@ type | |
storageCapacity*: uint64 | ||
|
||
PortalNode* = ref object | ||
state*: PortalNodeState | ||
discovery: protocol.Protocol | ||
contentDB: ContentDB | ||
streamManager: StreamManager | ||
|
@@ -41,6 +49,9 @@ type | |
stateNetwork*: Opt[StateNetwork] | ||
beaconLightClient*: Opt[LightClient] | ||
statusLogLoop: Future[void] | ||
metricsServer*: Opt[MetricsHttpServerRef] | ||
rpcHttpServer*: Opt[RpcHttpServer] | ||
rpcWsServer*: Opt[RpcWebSocketServer] | ||
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. I'm not a big fan of adding these to the Conceptually, to be a part of the Portal network as a node you don't require these more user faced features. If we want to make this more streamlined then I would rather create another object called 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. I see your point. Yeah I wasn't sure about this part either. Okay, I'll move them out and clean them up separately for now. I'll keep the PortalClient idea for a separate PR. |
||
|
||
# Beacon light client application callbacks triggered when new finalized header | ||
# or optimistic header is available. | ||
|
@@ -202,6 +213,8 @@ proc statusLogLoop(n: PortalNode) {.async: (raises: []).} = | |
proc start*(n: PortalNode) = | ||
debug "Starting Portal node" | ||
|
||
n.discovery.start() | ||
|
||
if n.beaconNetwork.isSome(): | ||
n.beaconNetwork.value.start() | ||
if n.historyNetwork.isSome(): | ||
|
@@ -214,18 +227,50 @@ proc start*(n: PortalNode) = | |
|
||
n.statusLogLoop = statusLogLoop(n) | ||
|
||
proc stop*(n: PortalNode) = | ||
n.state = PortalNodeState.Running | ||
|
||
proc stop*(n: PortalNode) {.async: (raises: []).} = | ||
debug "Stopping Portal node" | ||
|
||
if n.rpcWsServer.isSome(): | ||
let server = n.rpcWsServer.get() | ||
try: | ||
server.stop() | ||
await server.closeWait() | ||
except CatchableError as e: | ||
warn "Failed to stop rpc WS server", exc = e.name, err = e.msg | ||
|
||
if n.rpcHttpServer.isSome(): | ||
let server = n.rpcHttpServer.get() | ||
try: | ||
await server.stop() | ||
await server.closeWait() | ||
except CatchableError as e: | ||
warn "Failed to stop rpc HTTP server", exc = e.name, err = e.msg | ||
|
||
if n.metricsServer.isSome(): | ||
let server = n.metricsServer.get() | ||
try: | ||
await server.stop() | ||
await server.close() | ||
except CatchableError as e: | ||
warn "Failed to stop metrics HTTP server", exc = e.name, err = e.msg | ||
|
||
var futures: seq[Future[void]] | ||
|
||
if n.beaconNetwork.isSome(): | ||
n.beaconNetwork.value.stop() | ||
futures.add(n.beaconNetwork.value.stop()) | ||
if n.historyNetwork.isSome(): | ||
n.historyNetwork.value.stop() | ||
futures.add(n.historyNetwork.value.stop()) | ||
if n.stateNetwork.isSome(): | ||
n.stateNetwork.value.stop() | ||
|
||
futures.add(n.stateNetwork.value.stop()) | ||
if n.beaconLightClient.isSome(): | ||
n.beaconLightClient.value.stop() | ||
futures.add(n.beaconLightClient.value.stop()) | ||
if not n.statusLogLoop.isNil(): | ||
futures.add(n.statusLogLoop.cancelAndWait()) | ||
|
||
await noCancel(allFutures(futures)) | ||
|
||
if not n.statusLogLoop.isNil: | ||
n.statusLogLoop.cancelSoon() | ||
await n.discovery.closeWait() | ||
n.contentDB.close() | ||
n.statusLogLoop = nil |
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.
Had to change this to a ref object so that the stop proc can become async
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.
And making
LightClientManager
in the stop call avar
did not help?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.
I tried that and it didn't work. This was the error:
Error: 'self' is of type <var LightClientManager> which cannot be captured as it would violate memory safety, declared here: /home/user/development/status-im/nimbus-eth1/fluffy/network/beacon/beacon_light_client_manager.nim(323, 12); using '-d:nimNoLentIterators' helps in some cases. Consider using a <ref var LightClientManager> which can be captured.