diff --git a/packages/apps-engine/deno-runtime/handlers/app/handler.ts b/packages/apps-engine/deno-runtime/handlers/app/handler.ts index 5ec4831561b0..141e145df971 100644 --- a/packages/apps-engine/deno-runtime/handlers/app/handler.ts +++ b/packages/apps-engine/deno-runtime/handlers/app/handler.ts @@ -19,8 +19,8 @@ import handleOnUpdate from './handleOnUpdate.ts'; export default async function handleApp(method: string, params: unknown): Promise { const [, appMethod] = method.split(':'); - // We don't want the getStatus method to generate logs, so we handle it separately try { + // We don't want the getStatus method to generate logs, so we handle it separately if (appMethod === 'getStatus') { return await handleGetStatus(); } diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index b6c8a804aae3..bfd8ee4a99cc 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -5,18 +5,18 @@ import { type Readable, EventEmitter } from 'stream'; import debugFactory from 'debug'; import * as jsonrpc from 'jsonrpc-lite'; -import { LivenessManager } from './LivenessManager'; -import { ProcessMessenger } from './ProcessMessenger'; -import { bundleLegacyApp } from './bundler'; -import { decoder } from './codec'; import { AppStatus } from '../../../definition/AppStatus'; +import type { AppMethod } from '../../../definition/metadata'; import type { AppManager } from '../../AppManager'; import type { AppBridges } from '../../bridges'; import type { IParseAppPackageResult } from '../../compiler'; import { AppConsole, type ILoggerStorageEntry } from '../../logging'; import type { AppAccessorManager, AppApiManager } from '../../managers'; import type { AppLogStorage, IAppStorageItem } from '../../storage'; -import { AppMethod } from '../../../definition/metadata'; +import { LivenessManager } from './LivenessManager'; +import { ProcessMessenger } from './ProcessMessenger'; +import { bundleLegacyApp } from './bundler'; +import { decoder } from './codec'; const baseDebug = debugFactory('appsEngine:runtime:deno'); @@ -107,11 +107,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { private readonly livenessManager: LivenessManager; // We need to keep the appSource around in case the Deno process needs to be restarted - constructor( - manager: AppManager, - private readonly appPackage: IParseAppPackageResult, - private readonly storageItem: IAppStorageItem, - ) { + constructor(manager: AppManager, private readonly appPackage: IParseAppPackageResult, private readonly storageItem: IAppStorageItem) { super(); this.debug = baseDebug.extend(appPackage.info.id); @@ -321,12 +317,15 @@ export class DenoRuntimeSubprocessController extends EventEmitter { if (this.state === 'ready') { return; } + return new Promise((resolve, reject) => { let timeoutId: NodeJS.Timeout; + const handler = () => { clearTimeout(timeoutId); resolve(); }; + timeoutId = setTimeout(() => { this.off('ready', handler); reject(new Error(`[${this.getAppId()}] Timeout: app process not ready`)); diff --git a/packages/apps-engine/src/server/runtime/deno/ProcessMessenger.ts b/packages/apps-engine/src/server/runtime/deno/ProcessMessenger.ts index 03d03d125323..c919adb5f0bb 100644 --- a/packages/apps-engine/src/server/runtime/deno/ProcessMessenger.ts +++ b/packages/apps-engine/src/server/runtime/deno/ProcessMessenger.ts @@ -1,11 +1,11 @@ -import { ChildProcess } from 'child_process'; +import type { ChildProcess } from 'child_process'; import type { JsonRpc } from 'jsonrpc-lite'; import { encoder } from './codec'; export class ProcessMessenger { - private deno: ChildProcess; + private deno: ChildProcess | undefined; private _sendStrategy: (message: JsonRpc) => void; @@ -30,7 +30,7 @@ export class ProcessMessenger { } private switchStrategy() { - if (this.deno instanceof ChildProcess) { + if (this.deno?.stdin?.writable) { this._sendStrategy = this.strategySend.bind(this); } else { this._sendStrategy = this.strategyError.bind(this);