@cloudflare/sandbox 0.7.7 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -26
- package/dist/index.js.map +1 -1
- package/dist/sandbox-DGAjk7r3.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2712,7 +2712,7 @@ function buildS3fsSource(bucket, prefix) {
|
|
|
2712
2712
|
* This file is auto-updated by .github/changeset-version.ts during releases
|
|
2713
2713
|
* DO NOT EDIT MANUALLY - Changes will be overwritten on the next version bump
|
|
2714
2714
|
*/
|
|
2715
|
-
const SDK_VERSION = "0.7.
|
|
2715
|
+
const SDK_VERSION = "0.7.8";
|
|
2716
2716
|
|
|
2717
2717
|
//#endregion
|
|
2718
2718
|
//#region src/sandbox.ts
|
|
@@ -3138,34 +3138,43 @@ var Sandbox = class Sandbox extends Container {
|
|
|
3138
3138
|
*/
|
|
3139
3139
|
async containerFetch(requestOrUrl, portOrInit, portParam) {
|
|
3140
3140
|
const { request, port } = this.parseContainerFetchArgs(requestOrUrl, portOrInit, portParam);
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
this.
|
|
3162
|
-
return new Response("Container is starting. Please retry in a moment.", {
|
|
3141
|
+
const state = await this.getState();
|
|
3142
|
+
const containerRunning = this.ctx.container?.running;
|
|
3143
|
+
const staleStateDetected = state.status === "healthy" && containerRunning === false;
|
|
3144
|
+
if (state.status !== "healthy" || containerRunning === false) {
|
|
3145
|
+
if (staleStateDetected) this.logger.debug("Stale container state detected: persisted state is healthy but container is not running");
|
|
3146
|
+
try {
|
|
3147
|
+
this.logger.debug("Starting container with configured timeouts", {
|
|
3148
|
+
instanceTimeout: this.containerTimeouts.instanceGetTimeoutMS,
|
|
3149
|
+
portTimeout: this.containerTimeouts.portReadyTimeoutMS
|
|
3150
|
+
});
|
|
3151
|
+
await this.startAndWaitForPorts({
|
|
3152
|
+
ports: port,
|
|
3153
|
+
cancellationOptions: {
|
|
3154
|
+
instanceGetTimeoutMS: this.containerTimeouts.instanceGetTimeoutMS,
|
|
3155
|
+
portReadyTimeoutMS: this.containerTimeouts.portReadyTimeoutMS,
|
|
3156
|
+
waitInterval: this.containerTimeouts.waitIntervalMS,
|
|
3157
|
+
abort: request.signal
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
3160
|
+
} catch (e) {
|
|
3161
|
+
if (this.isNoInstanceError(e)) return new Response("Container is currently provisioning. This can take several minutes on first deployment. Please retry in a moment.", {
|
|
3163
3162
|
status: 503,
|
|
3164
|
-
headers: { "Retry-After": "
|
|
3163
|
+
headers: { "Retry-After": "10" }
|
|
3165
3164
|
});
|
|
3165
|
+
if (this.isTransientStartupError(e)) {
|
|
3166
|
+
if (staleStateDetected) {
|
|
3167
|
+
this.logger.warn("Container startup failed after stale state detection, aborting DO for recovery", { error: e instanceof Error ? e.message : String(e) });
|
|
3168
|
+
this.ctx.abort();
|
|
3169
|
+
} else this.logger.debug("Transient container startup error, returning 503", { error: e instanceof Error ? e.message : String(e) });
|
|
3170
|
+
return new Response("Container is starting. Please retry in a moment.", {
|
|
3171
|
+
status: 503,
|
|
3172
|
+
headers: { "Retry-After": "3" }
|
|
3173
|
+
});
|
|
3174
|
+
}
|
|
3175
|
+
this.logger.error("Container startup failed with permanent error", e instanceof Error ? e : new Error(String(e)));
|
|
3176
|
+
return new Response(`Failed to start container: ${e instanceof Error ? e.message : String(e)}`, { status: 500 });
|
|
3166
3177
|
}
|
|
3167
|
-
this.logger.error("Container startup failed with permanent error", e instanceof Error ? e : new Error(String(e)));
|
|
3168
|
-
return new Response(`Failed to start container: ${e instanceof Error ? e.message : String(e)}`, { status: 500 });
|
|
3169
3178
|
}
|
|
3170
3179
|
return await super.containerFetch(requestOrUrl, portOrInit, portParam);
|
|
3171
3180
|
}
|
|
@@ -3202,6 +3211,8 @@ var Sandbox = class Sandbox extends Container {
|
|
|
3202
3211
|
"network connection lost",
|
|
3203
3212
|
"container suddenly disconnected",
|
|
3204
3213
|
"monitor failed to find container",
|
|
3214
|
+
"container exited with unexpected exit code",
|
|
3215
|
+
"container exited before we could determine",
|
|
3205
3216
|
"timed out",
|
|
3206
3217
|
"timeout",
|
|
3207
3218
|
"the operation was aborted"
|