From aee3565a34bd9ffaea26d7abe78bff0943c8c3a9 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Fri, 31 Oct 2025 19:32:44 +0100 Subject: [PATCH 1/3] added healthcheck for default web sockets --- template/e2b.toml | 1 + template/server/main.py | 12 +++++++++++- template/server/messaging.py | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/template/e2b.toml b/template/e2b.toml index 1eb93ae1..f5f90e82 100644 --- a/template/e2b.toml +++ b/template/e2b.toml @@ -13,6 +13,7 @@ team_id = "460355b3-4f64-48f9-9a16-4442817f79f5" memory_mb = 1_024 start_cmd = "/root/.jupyter/start-up.sh" +ready_cmd = "curl -s -o /dev/null -w '200' http://localhost:49999/health | grep -q '200'" dockerfile = "e2b.Dockerfile" template_name = "code-interpreter-v1" template_id = "nlhz8vlwyupq845jsdg9" diff --git a/template/server/main.py b/template/server/main.py index ea89a9d8..24aa7dd9 100644 --- a/template/server/main.py +++ b/template/server/main.py @@ -65,7 +65,17 @@ async def lifespan(app: FastAPI): @app.get("/health") async def get_health(): - return "OK" + websockets_ready = True + for ws in default_websockets.values(): + if not ws in websockets or not websockets[ws].is_connected(): + websockets_ready = False + print(f"Context {ws} is not connected") + break + + if not websockets_ready: + return PlainTextResponse("Not ready", status_code=503) + + return PlainTextResponse("OK", status_code=200) @app.post("/execute") diff --git a/template/server/messaging.py b/template/server/messaging.py index 0b151f8e..32e7e474 100644 --- a/template/server/messaging.py +++ b/template/server/messaging.py @@ -542,6 +542,10 @@ async def _process_message(self, data: dict): else: logger.warning(f"[UNHANDLED MESSAGE TYPE]: {data['msg_type']}") + def is_connected(self) -> bool: + """Check if the websocket is connected and open""" + return self._ws is not None and self._ws.open + async def close(self): logger.debug(f"Closing WebSocket {self.context_id}") From 2c0289db1235498117c49d0074b370930aab7625 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Fri, 31 Oct 2025 19:51:31 +0100 Subject: [PATCH 2/3] updated readycmd --- template/e2b.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/e2b.toml b/template/e2b.toml index f5f90e82..14b27a91 100644 --- a/template/e2b.toml +++ b/template/e2b.toml @@ -13,7 +13,7 @@ team_id = "460355b3-4f64-48f9-9a16-4442817f79f5" memory_mb = 1_024 start_cmd = "/root/.jupyter/start-up.sh" -ready_cmd = "curl -s -o /dev/null -w '200' http://localhost:49999/health | grep -q '200'" +ready_cmd = "curl -sf http://localhost:49999/health" dockerfile = "e2b.Dockerfile" template_name = "code-interpreter-v1" template_id = "nlhz8vlwyupq845jsdg9" From 98184c9522c93184dad54eaa98256ec0142ab2e6 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Fri, 31 Oct 2025 19:54:05 +0100 Subject: [PATCH 3/3] web sockets not ready until they are --- template/server/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/template/server/main.py b/template/server/main.py index 24aa7dd9..d55bd24d 100644 --- a/template/server/main.py +++ b/template/server/main.py @@ -65,11 +65,10 @@ async def lifespan(app: FastAPI): @app.get("/health") async def get_health(): - websockets_ready = True + websockets_ready = False for ws in default_websockets.values(): - if not ws in websockets or not websockets[ws].is_connected(): - websockets_ready = False - print(f"Context {ws} is not connected") + if ws in websockets and websockets[ws].is_connected(): + websockets_ready = True break if not websockets_ready: