fix: LiveQuery server is not shut down properly when handleShutdown is called (#8491)
This commit is contained in:
@@ -212,11 +212,12 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
throw error;
|
||||
}
|
||||
|
||||
handleShutdown() {
|
||||
async handleShutdown() {
|
||||
if (!this.client) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
return this.client.close(false);
|
||||
await this.client.close(false);
|
||||
delete this.connectionPromise;
|
||||
}
|
||||
|
||||
_adaptiveCollection(name: string) {
|
||||
|
||||
@@ -1194,7 +1194,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
||||
const now = new Date().getTime();
|
||||
const helpers = this._pgp.helpers;
|
||||
debug('deleteAllClasses');
|
||||
|
||||
if (this._client?.$pool.ended) {
|
||||
return;
|
||||
}
|
||||
await this._client
|
||||
.task('delete-all-classes', async t => {
|
||||
try {
|
||||
|
||||
@@ -93,6 +93,21 @@ class ParseLiveQueryServer {
|
||||
}
|
||||
this._createSubscribers();
|
||||
}
|
||||
|
||||
async shutdown() {
|
||||
if (this.subscriber.isOpen) {
|
||||
await Promise.all([
|
||||
...[...this.clients.values()].map(client => client.parseWebSocket.ws.close()),
|
||||
this.parseWebSocketServer.close(),
|
||||
...Array.from(this.subscriber.subscriptions.keys()).map(key =>
|
||||
this.subscriber.unsubscribe(key)
|
||||
),
|
||||
this.subscriber.close?.(),
|
||||
]);
|
||||
}
|
||||
this.subscriber.isOpen = false;
|
||||
}
|
||||
|
||||
_createSubscribers() {
|
||||
const messageRecieved = (channel, messageStr) => {
|
||||
logger.verbose('Subscribe message %j', messageStr);
|
||||
|
||||
@@ -168,6 +168,12 @@ class ParseServer {
|
||||
if (cacheAdapter && typeof cacheAdapter.handleShutdown === 'function') {
|
||||
promises.push(cacheAdapter.handleShutdown());
|
||||
}
|
||||
if (this.liveQueryServer?.server?.close) {
|
||||
promises.push(new Promise(resolve => this.liveQueryServer.server.close(resolve)));
|
||||
}
|
||||
if (this.liveQueryServer) {
|
||||
promises.push(this.liveQueryServer.shutdown());
|
||||
}
|
||||
return (promises.length > 0 ? Promise.all(promises) : Promise.resolve()).then(() => {
|
||||
if (this.config.serverCloseComplete) {
|
||||
this.config.serverCloseComplete();
|
||||
|
||||
Reference in New Issue
Block a user