mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-17 03:51:27 +01:00
fix: Prevent data loss on server shutdown in DataManager
We should wait for the async pool to cleanly exit and finish all running tasks. 30 seconds is a lot but we don't want any data loss – If 30 seconds are exceeded there might just be something fundamentally broken in the (plugin) implementation (or a huge bulk action?)
This commit is contained in:
parent
c59884b87c
commit
4b738fdf78
@ -532,18 +532,28 @@ public class DataManager {
|
||||
* Close the database and shutdown the async pool
|
||||
*/
|
||||
public void shutdown() {
|
||||
asyncPool.shutdown();
|
||||
databaseConnector.closeConnection();
|
||||
this.asyncPool.shutdown();
|
||||
try {
|
||||
if (!this.asyncPool.awaitTermination(30, TimeUnit.SECONDS)) {
|
||||
this.plugin.getLogger().warning("Failed to shutdown the async DataManager pool in time. Forcing shutdown");
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
this.plugin.getLogger().warning("Error while shutting down the async DataManager pool: " + ex.getMessage());
|
||||
}
|
||||
this.asyncPool.shutdownNow();
|
||||
|
||||
this.databaseConnector.closeConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force shutdown the async pool and close the database
|
||||
*
|
||||
* @return Tasks that didn't finish in the async pool
|
||||
* @return Tasks that were still in the pool's queue
|
||||
*/
|
||||
public List<Runnable> shutdownNow() {
|
||||
databaseConnector.closeConnection();
|
||||
return asyncPool.shutdownNow();
|
||||
List<Runnable> tasksLeftInQueue = this.asyncPool.shutdownNow();
|
||||
this.databaseConnector.closeConnection();
|
||||
return tasksLeftInQueue;
|
||||
}
|
||||
|
||||
public void shutdownTaskQueue() {
|
||||
|
Loading…
Reference in New Issue
Block a user