-
Notifications
You must be signed in to change notification settings - Fork 216
Throw descriptive error when sandbox is killed mid-request #291
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
Open
mishushakov
wants to merge
3
commits into
main
Choose a base branch
from
mishushakov/handle-sandbox-killed-econnreset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@e2b/code-interpreter': patch | ||
| '@e2b/code-interpreter-python': patch | ||
| --- | ||
|
|
||
| Throw a descriptive `TimeoutError`/`TimeoutException` instead of a raw socket error (e.g. `ECONNRESET`) when the sandbox is killed or times out while a request (`runCode`/`run_code`, context management) is in progress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { TimeoutError } from 'e2b' | ||
| import { expect } from 'vitest' | ||
|
|
||
| import { isDebug, sandboxTest, wait } from './setup' | ||
|
|
||
| sandboxTest.skipIf(isDebug)( | ||
| 'runCode throws a descriptive error when the sandbox is killed during execution', | ||
| async ({ sandbox }) => { | ||
| const execution = sandbox.runCode('import time; time.sleep(60)') | ||
| const assertion = Promise.all([ | ||
| expect(execution).rejects.toThrowError( | ||
| /sandbox was killed while the request was in progress/ | ||
| ), | ||
| expect(execution).rejects.toBeInstanceOf(TimeoutError), | ||
| ]) | ||
|
|
||
| await wait(2_000) | ||
| await sandbox.kill() | ||
|
|
||
| await assertion | ||
| } | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from e2b import TimeoutException | ||
| from e2b_code_interpreter import AsyncSandbox | ||
|
|
||
|
|
||
| @pytest.mark.skip_debug | ||
| async def test_run_code_raises_when_sandbox_is_killed_during_execution( | ||
| async_sandbox: AsyncSandbox, | ||
| ): | ||
| execution = asyncio.create_task( | ||
| async_sandbox.run_code("import time; time.sleep(60)") | ||
| ) | ||
|
|
||
| await asyncio.sleep(2) | ||
| await async_sandbox.kill() | ||
|
|
||
| with pytest.raises( | ||
| TimeoutException, match="sandbox was killed while the request was in progress" | ||
| ): | ||
| await execution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import threading | ||
|
|
||
| import pytest | ||
|
|
||
| from e2b import TimeoutException | ||
| from e2b_code_interpreter import Sandbox | ||
|
|
||
|
|
||
| @pytest.mark.skip_debug | ||
| def test_run_code_raises_when_sandbox_is_killed_during_execution(sandbox: Sandbox): | ||
| timer = threading.Timer(2.0, sandbox.kill) | ||
| timer.start() | ||
|
|
||
| try: | ||
| with pytest.raises( | ||
| TimeoutException, | ||
| match="sandbox was killed while the request was in progress", | ||
| ): | ||
| sandbox.run_code("import time; time.sleep(60)") | ||
| finally: | ||
| timer.cancel() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kill test sleep too short
Medium Severity
The new kill-during-execution tests use
time.sleep(60)whilerunCode/run_coderely on the default execution timeout (60s in JS, 300s in Python). That ratio is far below the project’s 10×/100× guidance for interrupt-style execution tests, so on JS the run can hit the defaulttimeoutMsabort around the same time as the sleep ends instead of staying in-flight when the sandbox is killed.Additional Locations (2)
python/tests/async/test_async_killed.py#L13-L14python/tests/sync/test_killed.py#L18-L19Triggered by learned rule: Test sleep durations must far exceed test timeouts
Reviewed by Cursor Bugbot for commit 17cce6a. Configure here.