fix crash if ServerService is disposed before being started
This commit is contained in:
parent
08fcb7f88c
commit
0684691993
1 changed files with 5 additions and 2 deletions
|
|
@ -40,7 +40,7 @@ const _dirname = fileURLToPath(new URL('.', import.meta.url));
|
|||
@Injectable()
|
||||
export class ServerService implements OnApplicationShutdown {
|
||||
private logger: Logger;
|
||||
#fastify: FastifyInstance;
|
||||
#fastify?: FastifyInstance;
|
||||
|
||||
constructor(
|
||||
@Inject(DI.config)
|
||||
|
|
@ -316,7 +316,7 @@ export class ServerService implements OnApplicationShutdown {
|
|||
await this.streamingApiServerService.detach();
|
||||
|
||||
this.logger.info('Disconnecting HTTP clients....;');
|
||||
await this.#fastify.close();
|
||||
await this.#fastify?.close();
|
||||
|
||||
this.logger.info('Server disposed.');
|
||||
}
|
||||
|
|
@ -325,6 +325,9 @@ export class ServerService implements OnApplicationShutdown {
|
|||
* Get the Fastify instance for testing.
|
||||
*/
|
||||
public get fastify(): FastifyInstance {
|
||||
if (!this.#fastify) {
|
||||
throw new Error('Cannot get fastify before starting server');
|
||||
}
|
||||
return this.#fastify;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue