Terminate gracefully
majecty opened this issue · 1 comments
The current way of terminating Foundry is to drop all resources at the end of run_node function.
Since we didn't care about the order of drop, sometimes Foundry panics in the termination process since other resources are dropped without expectation.
In the worst case, the database can be corrupted in the termination process.
There are four types of entities that should be terminated.
This is the termination order.
-
Snapshot service
Since other code does not depend on the snapshot service. I will terminate the snapshot service first. -
Network
By terminating the network, Foundry will not receive any packet from the network. All packet sending will be ignored after termination. -
Shutdown client, miner, scheme
They are main threads that doing consensus, creating a block, reading, and writing state. They depends on each other. Terminating them looks difficult. My plan is below:3.0. The network was terminated before.
3.1. Make consensus algorithm stop. It will not send any request to the client or miner.
3.2. Waits until client and miner finishing their works(like verifying blocks or creating blocks)
3.3. If there is no work to client, miner, and tendermint, drop them at the same time. -
Utilities
There are db, timer_loop, logger, and account provider. They are used by the client, miner, and engine(scheme). Since they are terminated before, we can terminate utilities safely.