@depup/wrangler 4.129.0-depup.0 → 4.131.1-depup.0

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/README.md CHANGED
@@ -13,10 +13,10 @@ npm install @depup/wrangler
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [wrangler](https://www.npmjs.com/package/wrangler) @ 4.129.0 |
17
- | Processed | 2026-09-06 |
16
+ | Original | [wrangler](https://www.npmjs.com/package/wrangler) @ 4.131.1 |
17
+ | Processed | 2026-09-13 |
18
18
  | Smoke test | failed |
19
- | Deps updated | 4 |
19
+ | Deps updated | 3 |
20
20
 
21
21
  ## Dependency Changes
22
22
 
@@ -25,7 +25,6 @@ npm install @depup/wrangler
25
25
  | blake3-wasm | 2.1.5 | ^3.0.0 |
26
26
  | esbuild | 0.28.1 | ^0.28.2 |
27
27
  | path-to-regexp | 6.3.0 | ^8.4.2 |
28
- | workerd | 1.20260903.1 | ^1.20260905.1 |
29
28
 
30
29
  ---
31
30
 
package/changes.json CHANGED
@@ -11,12 +11,8 @@
11
11
  "path-to-regexp": {
12
12
  "from": "6.3.0",
13
13
  "to": "^8.4.2"
14
- },
15
- "workerd": {
16
- "from": "1.20260903.1",
17
- "to": "^1.20260905.1"
18
14
  }
19
15
  },
20
- "timestamp": "2026-09-06T01:01:14.039Z",
21
- "totalUpdated": 4
16
+ "timestamp": "2026-09-13T01:01:25.799Z",
17
+ "totalUpdated": 3
22
18
  }
@@ -3609,6 +3609,31 @@
3609
3609
  "description": "The Durable Objects being renamed.",
3610
3610
  "markdownDescription": "The Durable Objects being renamed."
3611
3611
  },
3612
+ "transferred_classes": {
3613
+ "type": "array",
3614
+ "items": {
3615
+ "type": "object",
3616
+ "properties": {
3617
+ "from": {
3618
+ "type": "string"
3619
+ },
3620
+ "from_script": {
3621
+ "type": "string"
3622
+ },
3623
+ "to": {
3624
+ "type": "string"
3625
+ }
3626
+ },
3627
+ "required": [
3628
+ "from",
3629
+ "from_script",
3630
+ "to"
3631
+ ],
3632
+ "additionalProperties": false
3633
+ },
3634
+ "description": "The Durable Objects being transferred from another Worker.",
3635
+ "markdownDescription": "The Durable Objects being transferred from another Worker."
3636
+ },
3612
3637
  "deleted_classes": {
3613
3638
  "type": "array",
3614
3639
  "items": {
@@ -4106,16 +4131,16 @@
4106
4131
  "additionalProperties": false,
4107
4132
  "properties": {
4108
4133
  "logpush": {
4109
- "$ref": "#/definitions/interface-769040647-11843-22205-769040647-0-567642004818536"
4134
+ "$ref": "#/definitions/interface-769040647-13628-23990-769040647-0-585492004818536"
4110
4135
  },
4111
4136
  "observability": {
4112
- "$ref": "#/definitions/interface-769040647-11843-22205-769040647-0-567642004818536"
4137
+ "$ref": "#/definitions/interface-769040647-13628-23990-769040647-0-585492004818536"
4113
4138
  },
4114
4139
  "limits": {
4115
- "$ref": "#/definitions/interface-769040647-11843-22205-769040647-0-567642004818536"
4140
+ "$ref": "#/definitions/interface-769040647-13628-23990-769040647-0-585492004818536"
4116
4141
  },
4117
4142
  "cache": {
4118
- "$ref": "#/definitions/interface-769040647-11843-22205-769040647-0-567642004818536"
4143
+ "$ref": "#/definitions/interface-769040647-13628-23990-769040647-0-585492004818536"
4119
4144
  },
4120
4145
  "define": {
4121
4146
  "type": "object",
@@ -5419,7 +5444,7 @@
5419
5444
  "description": "Configuration for Worker Previews.\n\nThis defines the settings used when creating Preview deployments. Previews are branches of your Worker's main instance used to test features during feature development outside of production.\n\nThe `previews` block contains any intentionally divergent configuration intended solely for Previews, including:\n- All non-inheritable properties (environment variables and bindings like KV, D1, R2, etc.)\n- Select inheritable properties: `logpush`, `observability`, `limits`, `cache`",
5420
5445
  "markdownDescription": "Configuration for Worker Previews.\n\nThis defines the settings used when creating Preview deployments.\nPreviews are branches of your Worker's main instance used to test features\nduring feature development outside of production.\n\nThe `previews` block contains any intentionally divergent configuration intended solely for Previews, including:\n- All non-inheritable properties (environment variables and bindings like KV, D1, R2, etc.)\n- Select inheritable properties: `logpush`, `observability`, `limits`, `cache`"
5421
5446
  },
5422
- "interface-769040647-11843-22205-769040647-0-567642004818536": {
5447
+ "interface-769040647-13628-23990-769040647-0-585492004818536": {
5423
5448
  "type": "object",
5424
5449
  "properties": {
5425
5450
  "name": {
@@ -6020,6 +6045,14 @@
6020
6045
  "description": "The path to a Dockerfile, or an image URI for the Cloudflare registry.",
6021
6046
  "markdownDescription": "The path to a Dockerfile, or an image URI for the Cloudflare registry."
6022
6047
  },
6048
+ "images": {
6049
+ "type": "object",
6050
+ "additionalProperties": {
6051
+ "$ref": "#/definitions/DurableObjectContainerImage"
6052
+ },
6053
+ "description": "Named images available to a Durable Object-managed container through `ctx.container.images` and `env.EXPERIMENTAL_CLOUDFLARE_CONTAINER_IMAGES[className]`.\n\nOnly supported when `scheduling_policy` is `\"durable_object\"`.",
6054
+ "markdownDescription": "Named images available to a Durable Object-managed container through\n`ctx.container.images` and\n`env.EXPERIMENTAL_CLOUDFLARE_CONTAINER_IMAGES[className]`.\n\nOnly supported when `scheduling_policy` is `\"durable_object\"`."
6055
+ },
6023
6056
  "image_build_context": {
6024
6057
  "type": "string",
6025
6058
  "description": "Build context of the application.",
@@ -6038,10 +6071,16 @@
6038
6071
  "description": "The class name of the Durable Object the container is connected to.",
6039
6072
  "markdownDescription": "The class name of the Durable Object the container is connected to."
6040
6073
  },
6074
+ "observability": {
6075
+ "$ref": "#/definitions/ContainerObservability",
6076
+ "description": "Specify the observability behavior of this container application.\n\nWhen set, this overrides the root `observability` config for this container.",
6077
+ "markdownDescription": "Specify the observability behavior of this container application.\n\nWhen set, this overrides the root `observability` config for this container."
6078
+ },
6041
6079
  "scheduling_policy": {
6042
6080
  "type": "string",
6043
6081
  "enum": [
6044
6082
  "default",
6083
+ "durable_object",
6045
6084
  "moon",
6046
6085
  "regional"
6047
6086
  ],
@@ -6226,12 +6265,73 @@
6226
6265
  "default": 0
6227
6266
  }
6228
6267
  },
6229
- "required": [
6230
- "image"
6268
+ "additionalProperties": false
6269
+ },
6270
+ "DurableObjectContainerImage": {
6271
+ "anyOf": [
6272
+ {
6273
+ "type": "object",
6274
+ "properties": {
6275
+ "dockerfile": {
6276
+ "type": "string",
6277
+ "description": "Path to the Dockerfile Wrangler builds and pushes.",
6278
+ "markdownDescription": "Path to the Dockerfile Wrangler builds and pushes."
6279
+ }
6280
+ },
6281
+ "required": [
6282
+ "dockerfile"
6283
+ ],
6284
+ "additionalProperties": false
6285
+ },
6286
+ {
6287
+ "type": "object",
6288
+ "properties": {
6289
+ "image": {
6290
+ "type": "string",
6291
+ "description": "Digest-pinned image in the account's managed registry.",
6292
+ "markdownDescription": "Digest-pinned image in the account's managed registry."
6293
+ }
6294
+ },
6295
+ "required": [
6296
+ "image"
6297
+ ],
6298
+ "additionalProperties": false
6299
+ }
6231
6300
  ],
6301
+ "description": "An image Wrangler prepares for a Durable Object-managed container.",
6302
+ "markdownDescription": "An image Wrangler prepares for a Durable Object-managed container."
6303
+ },
6304
+ "ContainerObservability": {
6305
+ "type": "object",
6306
+ "properties": {
6307
+ "enabled": {
6308
+ "type": "boolean",
6309
+ "description": "If observability is enabled for this container application",
6310
+ "markdownDescription": "If observability is enabled for this container application"
6311
+ },
6312
+ "logs": {
6313
+ "type": "object",
6314
+ "properties": {
6315
+ "enabled": {
6316
+ "type": "boolean"
6317
+ }
6318
+ },
6319
+ "additionalProperties": false
6320
+ },
6321
+ "target_instance_percentage": {
6322
+ "type": "number",
6323
+ "description": "Percentage of instances to target with application-level observability hot reloads. Mutually exclusive with `target_instance_count`.",
6324
+ "markdownDescription": "Percentage of instances to target with application-level observability hot reloads.\nMutually exclusive with `target_instance_count`."
6325
+ },
6326
+ "target_instance_count": {
6327
+ "type": "number",
6328
+ "description": "Number of instances to target with application-level observability hot reloads. Mutually exclusive with `target_instance_percentage`.",
6329
+ "markdownDescription": "Number of instances to target with application-level observability hot reloads.\nMutually exclusive with `target_instance_percentage`."
6330
+ }
6331
+ },
6232
6332
  "additionalProperties": false,
6233
- "description": "Configuration for a container application",
6234
- "markdownDescription": "Configuration for a container application"
6333
+ "description": "Configuration for a container application.",
6334
+ "markdownDescription": "Configuration for a container application."
6235
6335
  },
6236
6336
  "LocalS3Credentials": {
6237
6337
  "type": "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depup/wrangler",
3
- "version": "4.129.0-depup.0",
3
+ "version": "4.131.1-depup.0",
4
4
  "description": "Command-line interface for all things Cloudflare Workers (with updated dependencies)",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -73,17 +73,17 @@
73
73
  "esbuild": "^0.28.2",
74
74
  "path-to-regexp": "^8.4.2",
75
75
  "unenv": "2.0.0-rc.24",
76
- "workerd": "^1.20260905.1",
76
+ "workerd": "1.20260911.1",
77
+ "@cloudflare/unenv-preset": "2.16.1",
77
78
  "@cloudflare/kv-asset-handler": "0.5.0",
78
- "miniflare": "5.20260903.0-alpha",
79
- "@cloudflare/unenv-preset": "2.16.1"
79
+ "miniflare": "5.20260911.0-alpha"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@aws-sdk/client-s3": "^3.721.0",
83
83
  "@aws-sdk/s3-request-presigner": "^3.721.0",
84
84
  "@bomb.sh/tab": "^0.0.12",
85
85
  "@cloudflare/types": "6.18.4",
86
- "@cloudflare/workers-types": "^5.20260903.1",
86
+ "@cloudflare/workers-types": "^5.20260911.1",
87
87
  "@cspotcode/source-map-support": "0.8.1",
88
88
  "@netlify/build-info": "10.5.1",
89
89
  "@sentry/node": "^7.86.0",
@@ -144,7 +144,7 @@
144
144
  "resolve": "^1.22.8",
145
145
  "rosie-skills": "^0.8.1",
146
146
  "semiver": "^1.1.0",
147
- "shell-quote": "^1.8.1",
147
+ "shell-quote": "^1.9.0",
148
148
  "signal-exit": "4.1.0",
149
149
  "smol-toml": "1.5.2",
150
150
  "supports-color": "^9.2.2",
@@ -163,25 +163,25 @@
163
163
  "yaml": "^2.8.1",
164
164
  "yargs": "^17.7.2",
165
165
  "zod": "4.4.3",
166
- "@cloudflare/autoconfig": "0.4.2",
167
- "@cloudflare/cli-shared-helpers": "0.1.27",
168
- "@cloudflare/build-output-utils": "0.4.0",
169
- "@cloudflare/config": "0.10.0",
170
- "@cloudflare/containers-shared": "0.16.0",
171
- "@cloudflare/deploy-helpers": "0.10.1",
166
+ "@cloudflare/autoconfig": "0.4.4",
167
+ "@cloudflare/build-output-utils": "0.4.1",
168
+ "@cloudflare/config": "0.11.0",
169
+ "@cloudflare/cli-shared-helpers": "0.1.29",
172
170
  "@cloudflare/pages-functions": "0.1.0",
173
- "@cloudflare/pages-shared": "^0.13.176",
174
- "@cloudflare/workers-auth": "0.6.8",
175
- "@cloudflare/workflows-shared": "0.13.0",
171
+ "@cloudflare/deploy-helpers": "0.11.1",
172
+ "@cloudflare/containers-shared": "0.16.1",
173
+ "@cloudflare/pages-shared": "^0.13.180",
174
+ "@cloudflare/remote-bindings": "0.0.23",
175
+ "@cloudflare/runtime-types": "0.0.25",
176
176
  "@cloudflare/shared-ast-primitives": "1.1.0",
177
- "@cloudflare/workers-utils": "0.36.0",
178
- "@cloudflare/runtime-types": "0.0.21",
179
- "@cloudflare/remote-bindings": "0.0.19",
180
177
  "@cloudflare/workers-shared": "0.19.9",
181
- "@cloudflare/workers-tsconfig": "0.0.0"
178
+ "@cloudflare/workers-auth": "0.6.11",
179
+ "@cloudflare/workers-tsconfig": "0.0.0",
180
+ "@cloudflare/workers-utils": "0.38.0",
181
+ "@cloudflare/workflows-shared": "0.13.0"
182
182
  },
183
183
  "peerDependencies": {
184
- "@cloudflare/workers-types": "^5.20260903.1"
184
+ "@cloudflare/workers-types": "^5.20260911.1"
185
185
  },
186
186
  "peerDependenciesMeta": {
187
187
  "@cloudflare/workers-types": {
@@ -228,16 +228,12 @@
228
228
  "path-to-regexp": {
229
229
  "from": "6.3.0",
230
230
  "to": "^8.4.2"
231
- },
232
- "workerd": {
233
- "from": "1.20260903.1",
234
- "to": "^1.20260905.1"
235
231
  }
236
232
  },
237
- "depsUpdated": 4,
233
+ "depsUpdated": 3,
238
234
  "originalPackage": "wrangler",
239
- "originalVersion": "4.129.0",
240
- "processedAt": "2026-09-06T01:01:39.174Z",
235
+ "originalVersion": "4.131.1",
236
+ "processedAt": "2026-09-13T01:01:51.236Z",
241
237
  "smokeTest": "failed"
242
238
  }
243
239
  }
@@ -163,81 +163,164 @@ export class ProxyWorker implements DurableObject {
163
163
  }
164
164
  }
165
165
 
166
- // explicitly NOT await-ing this promise, we are in a loop and want to process the whole queue quickly + synchronously
167
- void fetch(userWorkerUrl, new Request(request, { headers }))
168
- .then(async (res) => {
169
- res = new Response(res.body, res);
170
- rewriteUrlRelatedHeaders(res.headers, innerUrl, outerUrl);
171
-
172
- await checkForPreviewTokenError(res, this.env, proxyData);
173
-
174
- if (isHtmlResponse(res)) {
175
- res = insertLiveReloadScript(request, res, this.env, proxyData);
176
- }
177
-
178
- if (isSseResponse(res)) {
179
- void sendMessageToProxyController(this.env, {
180
- type: "sseResponseDetected",
181
- });
182
- }
183
-
184
- deferredResponse.resolve(res);
185
- })
186
- .catch((error: Error) => {
187
- // errors here are network errors or from response post-processing
188
- // to catch only network errors, use the 2nd param of the fetch.then()
189
-
190
- // we have crossed an async boundary, so proxyData may have changed
191
- // if proxyData.userWorkerUrl has changed, it means there is a new downstream UserWorker
192
- // and that this error is stale since it was for a request to the old UserWorker
193
- // only report the error if the request still targets the current
194
- // UserWorker. isSameUserWorkerOrigin compares origin (not href) so a
195
- // genuine error on a non-root path isn't misread as a reload — see
196
- // its docs.
197
- if (
198
- isSameUserWorkerOrigin(userWorkerUrl, this.proxyData?.userWorkerUrl)
199
- ) {
200
- void sendMessageToProxyController(this.env, {
201
- type: "error",
202
- error: {
203
- name: error.name,
204
- message: error.message,
205
- stack: error.stack,
206
- cause: error.cause,
207
- },
208
- });
209
-
210
- deferredResponse.reject(error);
211
- }
212
-
213
- // if the request can be retried (subset of idempotent requests which have no body), requeue it
214
- else if (request.method === "GET" || request.method === "HEAD") {
215
- this.requestRetryQueue.set(request, deferredResponse);
216
- // we would only end up here if the downstream UserWorker is chang*ing*
217
- // i.e. we are in a `pause`d state and expecting a `play` message soon
218
- // this request will be processed (retried) when the `play` message arrives
219
- // for that reason, we do not need to call `this.processQueue` here
220
- // (but, also, it can't hurt to call it since it bails when
221
- // in a `pause`d state i.e. `this.proxyData` is undefined)
222
- }
223
-
224
- // if the request cannot be retried, respond with 503 Service Unavailable
225
- // important to note, this is not an (unexpected) error -- it is an acceptable flow of local development
226
- // it would be incorrect to retry non-idempotent requests
227
- // and would require cloning all body streams to avoid stream reuse (which is inefficient but not out of the question in the future)
228
- // this is a good enough UX for now since it solves the most common GET use-case
229
- else {
230
- deferredResponse.resolve(
231
- new Response(
232
- "Your worker restarted mid-request. Please try sending the request again. Only GET or HEAD requests are retried automatically.",
233
- {
234
- status: 503,
235
- headers: { "Retry-After": "0" },
236
- }
166
+ /**
167
+ * Sends the request to the UserWorker and settles `deferredResponse`
168
+ * with the outcome — or requeues the request if the UserWorker is
169
+ * mid-reload. The promise chain is deliberately not awaited (`void`):
170
+ * we are in a loop and want to process the whole queue quickly +
171
+ * synchronously.
172
+ *
173
+ * A connection-level failure (the `fetch` itself rejects, so no
174
+ * response was received) on a same-origin GET/HEAD request is retried
175
+ * before being reported — see the rejection handler.
176
+ *
177
+ * Kept as a `const` arrow function: the handlers re-read
178
+ * `this.proxyData` across async boundaries to detect UserWorker
179
+ * reloads, so they need the ProxyWorker's lexical `this`.
180
+ *
181
+ * @param attempt the number of attempts that have already failed
182
+ * (`0` on the first try)
183
+ */
184
+ const attemptUserWorkerFetch = (attempt = 0) =>
185
+ void fetch(userWorkerUrl, new Request(request, { headers }))
186
+ .then(
187
+ async (res) => {
188
+ if (attempt > 0) {
189
+ console.warn(
190
+ `ProxyWorker: ${request.method} ${request.url} recovered on attempt ${attempt + 1} after a dropped connection to the UserWorker`
191
+ );
192
+ }
193
+
194
+ res = new Response(res.body, res);
195
+ rewriteUrlRelatedHeaders(res.headers, innerUrl, outerUrl);
196
+
197
+ await checkForPreviewTokenError(res, this.env, proxyData);
198
+
199
+ if (isHtmlResponse(res)) {
200
+ res = insertLiveReloadScript(request, res, this.env, proxyData);
201
+ }
202
+
203
+ if (isSseResponse(res)) {
204
+ void sendMessageToProxyController(this.env, {
205
+ type: "sseResponseDetected",
206
+ });
207
+ }
208
+
209
+ deferredResponse.resolve(res);
210
+ },
211
+ (error: Error) => {
212
+ // the fetch itself rejected: a connection-level failure, and no
213
+ // response was received. Errors thrown while post-processing a
214
+ // received response skip this handler and land in the .catch
215
+ // below, so they are reported rather than retried and can never
216
+ // re-run the UserWorker's handler.
217
+ //
218
+ // When the UserWorker origin is unchanged (i.e. this is not a
219
+ // reload — see the same check in the .catch below), the failure
220
+ // is most commonly the UserWorker's HTTP server closing a reused
221
+ // keep-alive connection at the same moment this request was
222
+ // written to it (kj's client pool idleTimeout and server
223
+ // pipelineTimeout both default to 5s, so a connection idling ~5s
224
+ // races the close). Retrying bodyless requests draws a fresh
225
+ // connection and absorbs the race, mirroring the requeue in the
226
+ // .catch for reloads: retry immediately, then once more after
227
+ // 250ms (3 attempts in total).
228
+ if (
229
+ isSameUserWorkerOrigin(
230
+ userWorkerUrl,
231
+ this.proxyData?.userWorkerUrl
232
+ ) &&
233
+ (request.method === "GET" || request.method === "HEAD") &&
234
+ attempt < 2
235
+ ) {
236
+ setTimeout(
237
+ () => {
238
+ // the UserWorker may have started reloading while this
239
+ // retry was queued (even at 0ms — setTimeout defers to a
240
+ // later task). `proxyData` carries the destination AND the
241
+ // headers, so retrying with the captured one could reach
242
+ // the pre-reload Worker or send a stale preview token.
243
+ // Requeue instead and let the current proxyData rebuild it.
244
+ if (this.proxyData !== proxyData) {
245
+ this.requestRetryQueue.set(request, deferredResponse);
246
+ this.processQueue();
247
+ return;
248
+ }
249
+
250
+ attemptUserWorkerFetch(attempt + 1);
251
+ },
252
+ attempt === 0 ? 0 : 250
253
+ );
254
+ return;
255
+ }
256
+
257
+ throw error;
258
+ }
259
+ )
260
+ .catch((error: Error) => {
261
+ // errors here are from response post-processing, or connection-
262
+ // level failures rethrown by the rejection handler above (a
263
+ // non-retriable method, or the retry budget was exhausted)
264
+
265
+ // we have crossed an async boundary, so proxyData may have changed
266
+ // if proxyData.userWorkerUrl has changed, it means there is a new downstream UserWorker
267
+ // and that this error is stale since it was for a request to the old UserWorker
268
+ // only report the error if the request still targets the current
269
+ // UserWorker. isSameUserWorkerOrigin compares origin (not href) so a
270
+ // genuine error on a non-root path isn't misread as a reload — see
271
+ // its docs.
272
+ if (
273
+ isSameUserWorkerOrigin(
274
+ userWorkerUrl,
275
+ this.proxyData?.userWorkerUrl
237
276
  )
238
- );
239
- }
240
- });
277
+ ) {
278
+ const attemptsNote = ` (failed after ${attempt + 1} ${
279
+ attempt === 0 ? "attempt" : "attempts"
280
+ })`;
281
+ void sendMessageToProxyController(this.env, {
282
+ type: "error",
283
+ error: {
284
+ name: error.name,
285
+ message: `${request.method} ${request.url}${attemptsNote}: ${error.message}`,
286
+ stack: error.stack,
287
+ cause: error.cause,
288
+ },
289
+ });
290
+
291
+ deferredResponse.reject(error);
292
+ }
293
+
294
+ // if the request can be retried (subset of idempotent requests which have no body), requeue it
295
+ else if (request.method === "GET" || request.method === "HEAD") {
296
+ this.requestRetryQueue.set(request, deferredResponse);
297
+ // we would only end up here if the downstream UserWorker is chang*ing*
298
+ // i.e. we are in a `pause`d state and expecting a `play` message soon
299
+ // this request will be processed (retried) when the `play` message arrives
300
+ // for that reason, we do not need to call `this.processQueue` here
301
+ // (but, also, it can't hurt to call it since it bails when
302
+ // in a `pause`d state i.e. `this.proxyData` is undefined)
303
+ }
304
+
305
+ // if the request cannot be retried, respond with 503 Service Unavailable
306
+ // important to note, this is not an (unexpected) error -- it is an acceptable flow of local development
307
+ // it would be incorrect to retry non-idempotent requests
308
+ // and would require cloning all body streams to avoid stream reuse (which is inefficient but not out of the question in the future)
309
+ // this is a good enough UX for now since it solves the most common GET use-case
310
+ else {
311
+ deferredResponse.resolve(
312
+ new Response(
313
+ "Your worker restarted mid-request. Please try sending the request again. Only GET or HEAD requests are retried automatically.",
314
+ {
315
+ status: 503,
316
+ headers: { "Retry-After": "0" },
317
+ }
318
+ )
319
+ );
320
+ }
321
+ });
322
+
323
+ attemptUserWorkerFetch();
241
324
  }
242
325
  }
243
326
  }
@@ -139,26 +139,57 @@ var ProxyWorker = class {
139
139
  headers.set(key, value);
140
140
  }
141
141
  }
142
- void fetch(userWorkerUrl, new Request(request, { headers })).then(async (res) => {
143
- res = new Response(res.body, res);
144
- rewriteUrlRelatedHeaders(res.headers, innerUrl, outerUrl);
145
- await checkForPreviewTokenError(res, this.env, proxyData);
146
- if (isHtmlResponse(res)) {
147
- res = insertLiveReloadScript(request, res, this.env, proxyData);
142
+ const attemptUserWorkerFetch = (attempt = 0) => void fetch(userWorkerUrl, new Request(request, { headers })).then(
143
+ async (res) => {
144
+ if (attempt > 0) {
145
+ console.warn(
146
+ `ProxyWorker: ${request.method} ${request.url} recovered on attempt ${attempt + 1} after a dropped connection to the UserWorker`
147
+ );
148
+ }
149
+ res = new Response(res.body, res);
150
+ rewriteUrlRelatedHeaders(res.headers, innerUrl, outerUrl);
151
+ await checkForPreviewTokenError(res, this.env, proxyData);
152
+ if (isHtmlResponse(res)) {
153
+ res = insertLiveReloadScript(request, res, this.env, proxyData);
154
+ }
155
+ if (isSseResponse(res)) {
156
+ void sendMessageToProxyController(this.env, {
157
+ type: "sseResponseDetected"
158
+ });
159
+ }
160
+ deferredResponse.resolve(res);
161
+ },
162
+ (error) => {
163
+ if (isSameUserWorkerOrigin(
164
+ userWorkerUrl,
165
+ this.proxyData?.userWorkerUrl
166
+ ) && (request.method === "GET" || request.method === "HEAD") && attempt < 2) {
167
+ setTimeout(
168
+ () => {
169
+ if (this.proxyData !== proxyData) {
170
+ this.requestRetryQueue.set(request, deferredResponse);
171
+ this.processQueue();
172
+ return;
173
+ }
174
+ attemptUserWorkerFetch(attempt + 1);
175
+ },
176
+ attempt === 0 ? 0 : 250
177
+ );
178
+ return;
179
+ }
180
+ throw error;
148
181
  }
149
- if (isSseResponse(res)) {
150
- void sendMessageToProxyController(this.env, {
151
- type: "sseResponseDetected"
152
- });
153
- }
154
- deferredResponse.resolve(res);
155
- }).catch((error) => {
156
- if (isSameUserWorkerOrigin(userWorkerUrl, this.proxyData?.userWorkerUrl)) {
182
+ ).catch((error) => {
183
+ if (isSameUserWorkerOrigin(
184
+ userWorkerUrl,
185
+ this.proxyData?.userWorkerUrl
186
+ )) {
187
+ const attemptsNote = ` (failed after ${attempt + 1} ${attempt === 0 ? "attempt" : "attempts"})`;
157
188
  void sendMessageToProxyController(this.env, {
158
189
  type: "error",
159
190
  error: {
160
191
  name: error.name,
161
- message: error.message,
192
+ message: `${request.method} ${request.url}${attemptsNote}: ${error.message}`,
162
193
  stack: error.stack,
163
194
  cause: error.cause
164
195
  }
@@ -178,6 +209,7 @@ var ProxyWorker = class {
178
209
  );
179
210
  }
180
211
  });
212
+ attemptUserWorkerFetch();
181
213
  }
182
214
  }
183
215
  };