Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: terminalservice fork across cluster #1721

Merged
merged 7 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion plugins/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MediaCore } from './media-core';
import { checkLegacyLxc, checkLxc } from './platform/lxc';
import { ConsoleServiceNativeId, PluginSocketService, ReplServiceNativeId } from './plugin-socket-service';
import { ScriptCore, ScriptCoreNativeId, newScript } from './script-core';
import { TerminalService, TerminalServiceNativeId } from './terminal-service';
import { TerminalService, TerminalServiceNativeId, connectTTYStream } from './terminal-service';
import { UsersCore, UsersNativeId } from './user';
import { ClusterCore, ClusterCoreNativeId } from './cluster';

Expand Down Expand Up @@ -331,5 +331,6 @@ export async function fork() {
return {
tsCompile,
newScript,
connectTTYStream,
}
}
16 changes: 16 additions & 0 deletions plugins/core/src/terminal-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ export class TerminalService extends ScryptedDeviceBase implements StreamService
* EOF: { "eof": true }
*/
async connectStream(input: AsyncGenerator<Buffer | string, void>, options?: any): Promise<AsyncGenerator<Buffer, void>> {
if (options?.clusterWorkerId) {
const clusterWorkerId = options.clusterWorkerId;
delete options.clusterWorkerId;

const fork = sdk.fork<{
connectTTYStream: typeof connectTTYStream,
}>({ clusterWorkerId });
const result = await fork.result;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fork needs to be exited somehow

return result.connectTTYStream(input, options);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if fork.result throws, or connectTTYstream throws, I would also call fork.terminate to force immediate cleanup.

}

let cp: InteractiveTerminal | NoninteractiveTerminal = null;
const queue = createAsyncQueue<Buffer>();
const extraPaths = await this.getExtraPaths();
Expand Down Expand Up @@ -232,4 +243,9 @@ export class TerminalService extends ScryptedDeviceBase implements StreamService

return generator();
}
}

export async function connectTTYStream(input: AsyncGenerator<Buffer | string, void>, options?: any): Promise<AsyncGenerator<Buffer, void>> {
const terminalService = new TerminalService();
return terminalService.connectStream(input, options);
}