Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,11 @@ export class Application<ContainerBindings extends Record<any, any>> extends Mac
return
}

if (this.#terminating) {
debug('app is already being terminated')
return
}

const shutdownInReverseOrder = this.experimentalFlags.enabled('shutdownInReverseOrder')

debug('terminating app')
Expand Down
35 changes: 35 additions & 0 deletions tests/application/terminate.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
Loading