wrangler 4.128.0 → 4.129.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "4.128.0",
3
+ "version": "4.129.1",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "assembly",
@@ -66,17 +66,17 @@
66
66
  "esbuild": "0.28.1",
67
67
  "path-to-regexp": "6.3.0",
68
68
  "unenv": "2.0.0-rc.24",
69
- "workerd": "1.20260831.1",
69
+ "workerd": "1.20260907.1",
70
70
  "@cloudflare/kv-asset-handler": "0.5.0",
71
- "miniflare": "5.20260831.0-alpha",
72
- "@cloudflare/unenv-preset": "2.16.1"
71
+ "@cloudflare/unenv-preset": "2.16.1",
72
+ "miniflare": "5.20260907.0-alpha"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@aws-sdk/client-s3": "^3.721.0",
76
76
  "@aws-sdk/s3-request-presigner": "^3.721.0",
77
77
  "@bomb.sh/tab": "^0.0.12",
78
78
  "@cloudflare/types": "6.18.4",
79
- "@cloudflare/workers-types": "^5.20260831.1",
79
+ "@cloudflare/workers-types": "^5.20260907.1",
80
80
  "@cspotcode/source-map-support": "0.8.1",
81
81
  "@netlify/build-info": "10.5.1",
82
82
  "@sentry/node": "^7.86.0",
@@ -156,25 +156,25 @@
156
156
  "yaml": "^2.8.1",
157
157
  "yargs": "^17.7.2",
158
158
  "zod": "4.4.3",
159
- "@cloudflare/autoconfig": "0.4.1",
160
159
  "@cloudflare/build-output-utils": "0.4.0",
161
- "@cloudflare/cli-shared-helpers": "0.1.26",
160
+ "@cloudflare/autoconfig": "0.4.2",
161
+ "@cloudflare/cli-shared-helpers": "0.1.27",
162
162
  "@cloudflare/config": "0.10.0",
163
163
  "@cloudflare/containers-shared": "0.16.0",
164
- "@cloudflare/deploy-helpers": "0.10.0",
165
164
  "@cloudflare/pages-functions": "0.1.0",
166
- "@cloudflare/remote-bindings": "0.0.18",
167
- "@cloudflare/runtime-types": "0.0.20",
165
+ "@cloudflare/pages-shared": "^0.13.177",
166
+ "@cloudflare/remote-bindings": "0.0.20",
167
+ "@cloudflare/runtime-types": "0.0.22",
168
+ "@cloudflare/deploy-helpers": "0.10.2",
168
169
  "@cloudflare/shared-ast-primitives": "1.1.0",
169
- "@cloudflare/pages-shared": "^0.13.175",
170
+ "@cloudflare/workers-auth": "0.6.9",
170
171
  "@cloudflare/workers-shared": "0.19.9",
172
+ "@cloudflare/workers-utils": "0.36.0",
171
173
  "@cloudflare/workers-tsconfig": "0.0.0",
172
- "@cloudflare/workers-utils": "0.35.0",
173
- "@cloudflare/workflows-shared": "0.13.0",
174
- "@cloudflare/workers-auth": "0.6.7"
174
+ "@cloudflare/workflows-shared": "0.13.0"
175
175
  },
176
176
  "peerDependencies": {
177
- "@cloudflare/workers-types": "^5.20260831.1"
177
+ "@cloudflare/workers-types": "^5.20260907.1"
178
178
  },
179
179
  "peerDependenciesMeta": {
180
180
  "@cloudflare/workers-types": {
@@ -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
  };