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
+32-29Lines changed: 32 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,50 +235,53 @@ Once an invocation has six connections open, it can still attempt to open additi
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
236
- Earlier connections that are stalled<sup>1</sup> might get closed with a `Response closed due to connection limit` exception.
237
237
238
-
<sup>1</sup>A connections is considered stalled when it is not not being actively read from or written to, for example:
239
-
```js
240
-
// Within a for-of loop
241
-
constresponse=awaitfetch('https://example.org');
242
-
forawait (constchunkofresp.body) {
243
-
// While this code block is executing, there are no pending
244
-
// reads on the response.body. Accordingly, the system may view
245
-
// the stream as not being active within this block.
246
-
}
247
-
248
-
// Using body.getReader()
249
-
constreader=response.body.getReader();
250
-
let chunk =awaitreader.read();
251
-
awaitprocessChunk(chunk);
252
-
chunk =awaitreader.read();
253
-
awaitprocessChunk(chunk);
254
-
255
-
asyncfunctionprocessChunk(chunk) {
256
-
// The stream is considered inactive as there is no pending reads
257
-
// on response.body. It may then get cancelled.
258
-
}
259
-
```
260
-
261
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()`.
262
239
263
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:
264
241
265
242
```ts
266
-
let resp=awaitfetch(url);
243
+
const response=awaitfetch(url);
267
244
268
245
// Only read the response body for successful responses
269
-
if (resp.statusCode<=299) {
270
-
// 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
271
248
} else {
272
249
// Explicitly cancel it
273
-
resp.body.cancel();
250
+
response.body.cancel();
274
251
}
275
252
```
276
253
277
254
This will free up an open connection.
278
255
279
-
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.
257
+
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.
280
259
281
-
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.
260
+
<sup>1</sup>A connections is considered stalled when it is not not being
0 commit comments