Skip to content

Commit

Permalink
Merge pull request #109 from Thymis-io/fix/blocking-terminal
Browse files Browse the repository at this point in the history
Fix blocking terminal websocket
  • Loading branch information
MSchmoecker authored Oct 9, 2024
2 parents 266517d + 10603db commit 0a1911b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions controller/thymis_controller/routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, Query, Request, WebSocket
from fastapi.concurrency import run_in_threadpool
from fastapi.responses import FileResponse, RedirectResponse
from paramiko import PKey, SSHClient
from thymis_controller import crud, dependencies, models, modules, project, utils
Expand Down Expand Up @@ -284,8 +285,9 @@ async def terminal_websocket(
pkey: PKey = PKey.from_path(global_settings.SSH_KEY_PATH)

try:
client.connect(tcp_ip, tcp_port, "root", pkey=pkey)
channel = client.invoke_shell()
channel = await run_in_threadpool(
connect_to_ssh_shell, client, tcp_ip, tcp_port, pkey
)
except Exception as e:
await websocket.send_bytes(str(e).encode())
await websocket.close()
Expand All @@ -305,6 +307,11 @@ async def terminal_websocket(
client.close()


def connect_to_ssh_shell(client: SSHClient, tcp_ip: str, tcp_port: int, pkey: PKey):
client.connect(tcp_ip, tcp_port, "root", pkey=pkey, timeout=30)
return client.invoke_shell()


@router.get("/testSession")
def test_session(session: SessionAD):
session
Expand Down

0 comments on commit 0a1911b

Please sign in to comment.