diff --git a/app/server/lib/ActiveDoc.ts b/app/server/lib/ActiveDoc.ts index bcc32f66..65825729 100644 --- a/app/server/lib/ActiveDoc.ts +++ b/app/server/lib/ActiveDoc.ts @@ -34,7 +34,7 @@ import { TransformRule } from 'app/common/ActiveDocAPI'; import {ApiError} from 'app/common/ApiError'; -import {asyncOnce, mapGetOrSet, MapWithTTL} from 'app/common/AsyncCreate'; +import {mapGetOrSet, MapWithTTL} from 'app/common/AsyncCreate'; import {AttachmentColumns, gatherAttachmentIds, getAttachmentColumns} from 'app/common/AttachmentColumns'; import { BulkAddRecord, @@ -231,10 +231,7 @@ export class ActiveDoc extends EventEmitter { private _recoveryMode: boolean = false; private _shuttingDown: boolean = false; private _afterShutdownCallback?: () => Promise; - // catch & report error so that asyncOnce does not get cleared. - private _doShutdown = asyncOnce( - () => this._doShutdownImpl().catch((e) => log.error('Uncaught shutdown error', e)) - ); + private _doShutdown?: Promise; /** * In cases where large numbers of documents are restarted simultaneously @@ -501,10 +498,10 @@ export class ActiveDoc extends EventEmitter { if (options.afterShutdown) { this._afterShutdownCallback = options.afterShutdown; } - await this._doShutdown(); + this._doShutdown ||= this._doShutdownImpl(); + await this._doShutdown; } - private async _doShutdownImpl(): Promise { const docSession = makeExceptionalDocSession('system'); this._log.debug(docSession, "shutdown starting");