e2b-dev / E2B

Secure open source cloud runtime for AI apps & AI agents
https://e2b.dev/docs
Apache License 2.0
6.76k stars 431 forks source link

e2b-sandbox-refresh thread dies, can't recover #454

Open antonioalegria opened 2 hours ago

antonioalegria commented 2 hours ago

Describe the bug Sometimes the e2b-sandbox-refresh thread dies with the following exception:

[2024-10-07 23:04:29 - e2b.sandbox.websocket_client:71 - ERROR] WebSocket received error while receiving messages: sent 1011 (internal error) keepalive ping timeout; no close frame received
[2024-10-07 23:11:20 - e2b.sandbox.websocket_client:71 - ERROR] WebSocket received error while receiving messages: sent 1011 (internal error) keepalive ping timeout; no close frame received
Exception in thread e2b-sandbox-refresh:
Traceback (most recent call last):
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/e2b/sandbox/sandbox_connection.py", line 432, in _refresh
    api.sandboxes_sandbox_id_refreshes_post(
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/pydantic/validate_call_decorator.py", line 60, in wrapper_function
    return validate_call_wrapper(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/pydantic/_internal/_validate_call.py", line 96, in __call__
    res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/e2b/api/v2/client/api/sandboxes_api.py", line 1138, in sandboxes_sandbox_id_refreshes_post
    return self.api_client.response_deserialize(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/e2b/api/v2/client/api_client.py", line 299, in response_deserialize
    raise NotFoundException(http_resp=response_data)
e2b.api.v2.client.exceptions.NotFoundException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'content-type': 'application/json; charset=utf-8', 'date': 'Mon, 07 Oct 2024 22:11:21 GMT', 'Content-Length': '97', 'via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'})
HTTP response body: {"code":404,"message":"Error refreshing sandbox - sandbox 'i6m9aqyatdld3v8a2i1nc' was not found"}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/user/Developer/my-project/.venv/lib/python3.12/site-packages/e2b/sandbox/sandbox_connection.py", line 439, in _refresh
    raise SandboxException(
e2b.sandbox.exception.SandboxException: Sandbox i6m9aqyatdld3v8a2i1nc-b0b684e9 failed because it cannot be found

To Reproduce Steps to reproduce the behavior:

I haven't found reproduceable steps. Nonetheless, I would like for it to be possible to handle any errors coming from the e2b service and recover from them.

Expected behavior A clear and concise description of what you expected to happen.

It should be possible for the client code to detect and recover from such errors.

Desktop (please complete the following information):

linear[bot] commented 2 hours ago

E2B-1000 e2b-sandbox-refresh thread dies, can't recover