You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/platform/limits.mdx
+34-7Lines changed: 34 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,28 +233,55 @@ Once an invocation has six connections open, it can still attempt to open additi
233
233
234
234
- These attempts are put in a pending queue — the connections will not be initiated until one of the currently open connections has closed.
235
235
- Earlier connections can delay later ones, if a Worker tries to make many simultaneous subrequests, its later subrequests may appear to take longer to start.
236
+
- Earlier connections that are stalled<sup>1</sup> might get closed with a `Response closed due to connection limit` exception.
236
237
237
238
If you have cases in your application that use `fetch()` but that do not require consuming the response body, you can avoid the unread response body from consuming a concurrent connection by using `response.body.cancel()`.
238
239
239
240
For example, if you want to check whether the HTTP response code is successful (2xx) before consuming the body, you should explicitly cancel the pending response body:
240
241
241
242
```ts
242
-
let resp=awaitfetch(url);
243
+
const response=awaitfetch(url);
243
244
244
245
// Only read the response body for successful responses
245
-
if (resp.statusCode<=299) {
246
-
// Call resp.json(), resp.text() or otherwise process the body
246
+
if (response.statusCode<=299) {
247
+
// Call response.json(), response.text() or otherwise process the body
247
248
} else {
248
249
// Explicitly cancel it
249
-
resp.body.cancel();
250
+
response.body.cancel();
250
251
}
251
252
```
252
253
253
254
This will free up an open connection.
254
255
255
-
If the system detects that a Worker is deadlocked on open connections — for example, if the Worker has pending connection attempts but has no in-progress reads or writes on the connections that it already has open — then the least-recently-used open connection will be canceled to unblock the Worker.
256
+
If the system detects that a Worker is deadlocked on stalled connections<sup>1</sup> — for example, if the Worker has pending connection attempts but has no in-progress reads or writes on the connections that it already has open — then the least-recently-used open connection will be canceled to unblock the Worker.
256
257
257
-
If the Worker later attempts to use a canceled connection, an exception will be thrown. These exceptions should rarely occur in practice, though, since it is uncommon for a Worker to open a connection that it does not have an immediate use for.
258
+
If the Worker later attempts to use a canceled connection, a `Response closed due to connection limit` exception will be thrown. These exceptions should rarely occur in practice, though, since it is uncommon for a Worker to open a connection that it does not have an immediate use for.
259
+
260
+
<sup>1</sup>A connections is considered stalled when it is not not being
// The stream is considered inactive as there is no pending reads
282
+
// on response.body. It may then get cancelled.
283
+
}
284
+
```
258
285
259
286
:::note
260
287
@@ -294,7 +321,7 @@ To reduce the upload size of a Worker, consider some of the following strategies
294
321
295
322
- Removing unnecessary dependencies and packages
296
323
- Storing configuration files, static assets, and binary data using [Workers KV](/kv/), [R2](/r2/), [D1](/d1/), or [Workers Static Assets](/workers/static-assets/) instead of bundling them within your Worker code.
297
-
-Splitng functionality across multiple Workers and connecting them using [Service bindings](/workers/runtime-apis/bindings/service-bindings/).
324
+
-Splitting functionality across multiple Workers and connecting them using [Service bindings](/workers/runtime-apis/bindings/service-bindings/).
0 commit comments