Skip to content

Commit a0f76f9

Browse files
fix timeout
1 parent 5598377 commit a0f76f9

File tree

5 files changed

+59
-36
lines changed

5 files changed

+59
-36
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@hey-api/openapi-ts": "^0.63.2",
7070
"@msgpack/msgpack": "^3.1.0",
7171
"@types/blessed": "^0.1.25",
72+
"@types/node": "^22.15.30",
7273
"@types/react": "^19.1.5",
7374
"@types/yargs": "^17.0.33",
7475
"blessed": "^0.1.81",
@@ -89,16 +90,16 @@
8990
"yargs": "^17.7.2"
9091
},
9192
"dependencies": {
93+
"@codesandbox/pitcher-protocol": "0.360.4",
9294
"@inkjs/ui": "^2.0.0",
9395
"@tanstack/react-query": "^5.76.1",
94-
"isbinaryfile": "^5.0.4",
9596
"ink": "^5.2.1",
96-
"react": "^18.3.1",
97-
"@codesandbox/pitcher-protocol": "0.360.4",
97+
"isbinaryfile": "^5.0.4",
9898
"ora": "^8.2.0",
9999
"path": "^0.12.7",
100+
"react": "^18.3.1",
100101
"readline": "^1.3.0",
101-
"ws": "^8.18.2",
102-
"util": "^0.12.5"
102+
"util": "^0.12.5",
103+
"ws": "^8.18.2"
103104
}
104105
}

src/Sandbox.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ export class Sandbox {
150150
}
151151

152152
return customSession.git
153-
? {
154-
...customSession.env,
155-
GIT_CONFIG: "$HOME/private/.gitconfig",
156-
}
153+
? { GIT_CONFIG: "$HOME/private/.gitconfig", ...customSession.env }
157154
: customSession.env;
158155
}
159156

@@ -216,6 +213,8 @@ export class Sandbox {
216213
`[user]
217214
name = ${customSession.git.name || customSession.id}
218215
email = ${customSession.git.email}
216+
[init]
217+
defaultBranch = main
219218
[credential]
220219
helper = store --file ~/private/.gitcredentials`,
221220
{

src/Sandboxes.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,48 @@ export async function startVm(
3232
sandboxId: string,
3333
startOpts?: StartSandboxOpts
3434
): Promise<PitcherManagerResponse> {
35-
const startResult = await vmStart({
36-
client: apiClient,
37-
body: startOpts
38-
? {
39-
ipcountry: startOpts.ipcountry,
40-
tier: startOpts.vmTier?.name,
41-
hibernation_timeout_seconds: startOpts.hibernationTimeoutSeconds,
42-
automatic_wakeup_config: startOpts.automaticWakeupConfig,
43-
}
44-
: undefined,
45-
path: {
46-
id: sandboxId,
47-
},
48-
});
35+
// 2 minutes is the configuration for the API and Manager
36+
const TIMEOUT_SECONDS = 120;
37+
const controller = new AbortController();
38+
const signal = controller.signal;
39+
const timeoutHandle = setTimeout(() => {
40+
controller.abort();
41+
}, TIMEOUT_SECONDS * 1000);
42+
43+
try {
44+
const startResult = await vmStart({
45+
client: apiClient,
46+
body: startOpts
47+
? {
48+
ipcountry: startOpts.ipcountry,
49+
tier: startOpts.vmTier?.name,
50+
hibernation_timeout_seconds: startOpts.hibernationTimeoutSeconds,
51+
automatic_wakeup_config: startOpts.automaticWakeupConfig,
52+
}
53+
: undefined,
54+
path: {
55+
id: sandboxId,
56+
},
57+
signal,
58+
});
4959

50-
const response = handleResponse(
51-
startResult,
52-
`Failed to start sandbox ${sandboxId}`
53-
);
60+
const response = handleResponse(
61+
startResult,
62+
`Failed to start sandbox ${sandboxId}`
63+
);
5464

55-
return getStartResponse(response);
65+
return getStartResponse(response);
66+
} catch (err) {
67+
if (err instanceof Error && err.name === "AbortError") {
68+
throw new Error(
69+
`Request took longer than ${TIMEOUT_SECONDS}s, so we aborted.`
70+
);
71+
}
72+
73+
throw err;
74+
} finally {
75+
clearTimeout(timeoutHandle);
76+
}
5677
}
5778

5879
/**

src/Session/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ export class Commands {
5555
let commandWithEnv = Object.keys(allEnv).length
5656
? `env ${Object.entries(allEnv)
5757
.map(([key, value]) => `${key}=${value}`)
58-
.join(" ")} ${command}`
58+
.join(" ")} bash -c '${command}'`
5959
: command;
6060

6161
if (opts?.cwd) {
6262
commandWithEnv = `cd ${opts.cwd} && ${commandWithEnv}`;
6363
}
6464

65+
console.log("WTF", commandWithEnv);
66+
6567
const shell = await this.agentClient.shells.create(
6668
this.agentClient.workspacePath,
6769
opts?.dimensions ?? DEFAULT_SHELL_SIZE,

0 commit comments

Comments
 (0)