From 62df044fc1abb7d53f39fe21cf1d50d80ead86cb Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:46:41 +0000 Subject: [PATCH] Revert "fix: prevent deadlocks in node manager operations" This reverts commit ce92e415d8c74d70253f8d4170691d8e6cedce42. --- .../src/utils/node-manager.ts | 104 ++++++------------ 1 file changed, 33 insertions(+), 71 deletions(-) diff --git a/apps/shinkai-visor-e2e/src/utils/node-manager.ts b/apps/shinkai-visor-e2e/src/utils/node-manager.ts index a2c45c06c..383b379ac 100644 --- a/apps/shinkai-visor-e2e/src/utils/node-manager.ts +++ b/apps/shinkai-visor-e2e/src/utils/node-manager.ts @@ -16,7 +16,6 @@ export class NodeManager { private node: ChildProcess | undefined; private nodeExecPath: string; - private operationLock: Promise = Promise.resolve(); constructor(nodeExecPath?: string) { this.nodeExecPath = @@ -36,17 +35,6 @@ export class NodeManager { ); } - private async acquireLock(): Promise<() => void> { - let release: () => void; - const newLock = new Promise((resolve) => { - release = resolve; - }); - const oldLock = this.operationLock; - this.operationLock = newLock; - await oldLock; - return release!; - } - private async spawnNode( command: string, options: { @@ -65,31 +53,19 @@ export class NodeManager { stdio: 'pipe', shell: true, }); - - const cleanup = () => { - childProcess.removeAllListeners(); - childProcess.stdout?.removeAllListeners(); - childProcess.stderr?.removeAllListeners(); - }; - childProcess.on('close', (err) => { logger(`close with code ${String(err)}`); - cleanup(); reject(err); }); - childProcess.on('error', (err) => { logger(`error ${String(err)}`); }); - childProcess.stderr.on('error', (data) => { logger(String(data)); }); - childProcess.stdout.on('error', (data) => { logger(String(data)); }); - if (options.pipeLogs) { childProcess.stderr.on('data', (data) => { logger(data.toString()); @@ -98,21 +74,17 @@ export class NodeManager { logger(data.toString()); }); } - if (options.readyMatcher) { const timeoutRef = setTimeout(() => { childProcess.kill(); - cleanup(); reject( `ready matcher timeout after ${options.readyMatcherTimeoutMs}`, ); }, options.readyMatcherTimeoutMs ?? 15000); - childProcess.stdout?.on('data', (chunk: Buffer) => { if (options.readyMatcher?.test(chunk.toString())) { logger(`process ready, with readyMatcher:${chunk.toString()}`); clearTimeout(timeoutRef); - cleanup(); resolve(childProcess); } }); @@ -123,55 +95,45 @@ export class NodeManager { } async startNode(pristine: boolean, nodeOptions?: object): Promise { - const release = await this.acquireLock(); console.log('starting node'); - try { - const mergedOptions = { - ...this.defaultNodeOptions, - ...(nodeOptions || {}), - }; - if (pristine) { - this.resetToPristine(mergedOptions.NODE_STORAGE_PATH); - } - const nodeEnv = Object.entries(mergedOptions) - .map(([key, value]) => { - return `${key}="${value}"`; - }) - .join(' '); - - this.node = await this.spawnNode(`${nodeEnv} ${this.nodeExecPath}`, { - pipeLogs: true, - logsId: 'shinkai-node', - readyMatcher: /Server::run/, - }); - console.log('node started'); - } finally { - release(); + const mergedOptions = { + ...this.defaultNodeOptions, + ...(nodeOptions || {}), + }; + if (pristine) { + this.resetToPristine(mergedOptions.NODE_STORAGE_PATH); } + const nodeEnv = Object.entries(mergedOptions) + .map(([key, value]) => { + return `${key}="${value}"`; + }) + .join(' '); + + this.node = await this.spawnNode(`${nodeEnv} ${this.nodeExecPath}`, { + pipeLogs: true, + logsId: 'shinkai-node', + readyMatcher: /Server::run/, + }); + console.log('node started'); } async stopNode(): Promise { - const release = await this.acquireLock(); console.log('stopping node'); - try { - if (!this.node) { - return Promise.resolve(); - } - this.node.kill(); - await new Promise((resolve) => { - const timeout = setTimeout(() => { - console.warn('stopping node timeout'); - resolve(); - }, 5000); - this.node.once('exit', () => { - console.log('stopping node success'); - clearTimeout(timeout); - resolve(); - }); - }); - this.node = undefined; - } finally { - release(); + if (!this.node) { + return Promise.resolve(); } + this.node.kill(); + await new Promise((resolve) => { + const timeout = setTimeout(() => { + console.warn('stopping node timeout'); + resolve(); + }, 5000); + this.node.once('exit', () => { + console.log('stopping node success'); + clearTimeout(timeout); + resolve(); + }); + }); + this.node = undefined; } }