Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions template/e2b.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -sf http://localhost:49999/health"
dockerfile = "e2b.Dockerfile"
template_name = "code-interpreter-v1"
template_id = "nlhz8vlwyupq845jsdg9"
12 changes: 11 additions & 1 deletion template/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ async def lifespan(app: FastAPI):

@app.get("/health")
async def get_health():
return "OK"
websockets_ready = True
Copy link
Member

Choose a reason for hiding this comment

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

are you getting some 503s?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jakubno never during start, because it calls connect on create_context

Copy link
Member Author

Choose a reason for hiding this comment

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

I am getting "curl: (52) Empty reply from server" instead, because health check endpoint is not up

for ws in default_websockets.values():
Copy link

Choose a reason for hiding this comment

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

Bug: Race Condition in Health Check Iteration

The health check has a race condition. It iterates over default_websockets.values() without acquiring a lock, while default_websockets (a LockedMap) is modified concurrently elsewhere. This can lead to inconsistent health check results or iteration exceptions.

Fix in Cursor Fix in Web

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")
Expand Down
4 changes: 4 additions & 0 deletions template/server/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
Loading