diff --git a/src/core/config/GowsEngineConfigService.ts b/src/core/config/GowsEngineConfigService.ts index c16714d5..e8ff14c9 100644 --- a/src/core/config/GowsEngineConfigService.ts +++ b/src/core/config/GowsEngineConfigService.ts @@ -1,16 +1,21 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; +import { WhatsappConfigService } from '@waha/config.service'; import { BootstrapConfig } from '@waha/core/engines/gows/GowsBootstrap'; import { GowsConfig } from '@waha/core/engines/gows/session.gows.core'; @Injectable() export class GowsEngineConfigService { - constructor(protected configService: ConfigService) {} + constructor( + protected configService: ConfigService, + protected whatsappConfigService: WhatsappConfigService, + ) {} getBootstrapConfig(): BootstrapConfig { return { path: this.configService.get('WAHA_GOWS_PATH'), socket: this.getSocket(), + pprof: this.whatsappConfigService.debugModeEnabled, }; } diff --git a/src/core/engines/gows/GowsBootstrap.ts b/src/core/engines/gows/GowsBootstrap.ts index d2653999..24601734 100644 --- a/src/core/engines/gows/GowsBootstrap.ts +++ b/src/core/engines/gows/GowsBootstrap.ts @@ -22,6 +22,7 @@ export async function isUnixSocket(socketPath: string): Promise { export interface BootstrapConfig { path: string; socket: string; + pprof?: boolean; } export class GowsBootstrap implements EngineBootstrap { @@ -44,6 +45,7 @@ export class GowsBootstrap implements EngineBootstrap { this.logger, this.config.path, this.config.socket, + this.config.pprof, ); this.gows.start(() => { this.logger.info(`GOWS stopped, exiting...`); diff --git a/src/core/engines/gows/GowsSubprocess.ts b/src/core/engines/gows/GowsSubprocess.ts index d7ef828d..f4442f55 100644 --- a/src/core/engines/gows/GowsSubprocess.ts +++ b/src/core/engines/gows/GowsSubprocess.ts @@ -14,13 +14,21 @@ export class GowsSubprocess { private logger: Logger, readonly path: string, readonly socket: string, + readonly pprof: boolean = false, ) {} start(onExit: (code: number) => void) { this.logger.info('Starting GOWS subprocess...'); this.logger.debug(`GOWS path '${this.path}', socket: '${this.socket}'...`); - this.child = spawn(this.path, ['--socket', this.socket], { + const args = ['--socket', this.socket]; + if (this.pprof) { + this.logger.info('Debug mode enabled, adding pprof flags'); + args.push('--pprof'); + args.push('--pprof-port=6060'); + } + + this.child = spawn(this.path, args, { detached: true, }); this.logger.debug(`GOWS started with PID: ${this.child.pid}`);