Skip to content

Commit 1e8d07a

Browse files
authored
Merge branch 'main' into return-correct-status-code-for-non-existing-sandbox-in-keep-alive
2 parents 66fa7da + 2b1fdf8 commit 1e8d07a

5 files changed

Lines changed: 66 additions & 2 deletions

File tree

iac/provider-gcp/nomad/jobs/template-manager.hcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ job "template-manager-system" {
7373
OTEL_COLLECTOR_GRPC_ENDPOINT = "${otel_collector_grpc_endpoint}"
7474
LOGS_COLLECTOR_ADDRESS = "${logs_collector_address}"
7575
ORCHESTRATOR_SERVICES = "${orchestrator_services}"
76-
ALLOW_SANDBOX_INTERNET = "${allow_sandbox_internet}"
7776
SHARED_CHUNK_CACHE_PATH = "${shared_chunk_cache_path}"
7877
CLICKHOUSE_CONNECTION_STRING = "${clickhouse_connection_string}"
7978
DOCKERHUB_REMOTE_REPOSITORY_URL = "${dockerhub_remote_repository_url}"

iac/provider-gcp/nomad/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ resource "nomad_job" "template_manager" {
527527
otel_collector_grpc_endpoint = "localhost:${var.otel_collector_grpc_port}"
528528
logs_collector_address = "http://localhost:${var.logs_proxy_port.port}"
529529
orchestrator_services = "template-manager"
530-
allow_sandbox_internet = var.allow_sandbox_internet
531530
clickhouse_connection_string = local.clickhouse_connection_string
532531
dockerhub_remote_repository_url = var.dockerhub_remote_repository_url
533532
launch_darkly_api_key = trimspace(data.google_secret_manager_secret_version.launch_darkly_api_key.secret_data)

packages/api/internal/orchestrator/keep_alive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func (o *Orchestrator) KeepAliveFor(ctx context.Context, sandboxID string, durat
2323
now := time.Now()
2424

2525
updateFunc := func(sbx sandbox.Sandbox) (sandbox.Sandbox, error) {
26+
if sbx.State != sandbox.StateRunning {
27+
return sbx, &sandbox.NotFoundError{SandboxID: sandboxID}
28+
}
29+
2630
maxAllowedTTL := getMaxAllowedTTL(now, sbx.StartTime, duration, sbx.MaxInstanceLength)
2731
newEndTime := now.Add(maxAllowedTTL)
2832

packages/api/internal/sandbox/store/memory/operations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (s *Store) Update(sandboxID string, updateFunc func(sandbox.Sandbox) (sandb
120120

121121
item.mu.Lock()
122122
defer item.mu.Unlock()
123+
123124
sbx, err := updateFunc(item._data)
124125
if err != nil {
125126
return sandbox.Sandbox{}, err
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package sandboxes
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"testing"
7+
"time"
8+
9+
"github.com/stretchr/testify/require"
10+
"golang.org/x/sync/errgroup"
11+
12+
"github.com/e2b-dev/infra/tests/integration/internal/api"
13+
"github.com/e2b-dev/infra/tests/integration/internal/setup"
14+
"github.com/e2b-dev/infra/tests/integration/internal/utils"
15+
)
16+
17+
func TestSandboxSetTimeoutPausingSandbox(t *testing.T) {
18+
c := setup.GetAPIClient()
19+
20+
t.Run("test set timeout while pausing", func(t *testing.T) {
21+
sbx := utils.SetupSandboxWithCleanup(t, c, utils.WithAutoPause(true))
22+
sbxId := sbx.SandboxID
23+
24+
// Pause the sandbox
25+
wg := errgroup.Group{}
26+
wg.Go(func() error {
27+
pauseResp, err := c.PostSandboxesSandboxIDPauseWithResponse(t.Context(), sbxId, setup.WithAPIKey())
28+
if err != nil {
29+
return err
30+
}
31+
32+
if pauseResp.StatusCode() != http.StatusNoContent {
33+
return fmt.Errorf("unexpected status code: %d", pauseResp.StatusCode())
34+
}
35+
36+
return nil
37+
})
38+
39+
for range 5 {
40+
time.Sleep(200 * time.Millisecond)
41+
wg.Go(func() error {
42+
setTimeoutResp, err := c.PostSandboxesSandboxIDTimeoutWithResponse(t.Context(), sbxId, api.PostSandboxesSandboxIDTimeoutJSONRequestBody{
43+
Timeout: 15,
44+
},
45+
setup.WithAPIKey())
46+
if err != nil {
47+
return err
48+
}
49+
50+
if setTimeoutResp.StatusCode() != http.StatusNotFound {
51+
return fmt.Errorf("unexpected status code: %d", setTimeoutResp.StatusCode())
52+
}
53+
54+
return nil
55+
})
56+
}
57+
58+
err := wg.Wait()
59+
require.NoError(t, err)
60+
})
61+
}

0 commit comments

Comments
 (0)