diff --git a/package.json b/package.json index 787d96f..d9e68ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@adonisjs/application", - "version": "8.4.1", + "version": "8.4.2", "description": "AdonisJS application class to read app related data", "type": "module", "main": "build/index.js", diff --git a/src/application.ts b/src/application.ts index 93573aa..ea12a57 100644 --- a/src/application.ts +++ b/src/application.ts @@ -624,6 +624,11 @@ export class Application> extends Mac return } + if (this.#terminating) { + debug('app is already being terminated') + return + } + const shutdownInReverseOrder = this.experimentalFlags.enabled('shutdownInReverseOrder') debug('terminating app') diff --git a/tests/application/terminate.spec.ts b/tests/application/terminate.spec.ts new file mode 100644 index 0000000..4fadf84 --- /dev/null +++ b/tests/application/terminate.spec.ts @@ -0,0 +1,35 @@ +/* + * @adonisjs/application + * + * (c) AdonisJS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { test } from '@japa/runner' +import { Application } from '../../src/application.js' + +const BASE_URL = new URL('./app/', import.meta.url) + +test.group('Application | terminate', () => { + test('do not terminate app multiple times', async ({ assert }) => { + const stack: string[] = [] + + const app = new Application(BASE_URL, { + environment: 'web', + }) + + await app.init() + await app.boot() + + app.terminating(() => { + stack.push('terminating') + }) + + await Promise.all([app.terminate(), app.terminate()]) + + assert.deepEqual(stack, ['terminating']) + assert.equal(app.getState(), 'terminated') + }) +})