Skip to content

Commit bc83ca2

Browse files
committed
fixup!
1 parent 5c4bab7 commit bc83ca2

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/content/docs/workers/platform/limits.mdx

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -235,50 +235,53 @@ Once an invocation has six connections open, it can still attempt to open additi
235235
- 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.
236236
- Earlier connections that are stalled<sup>1</sup> might get closed with a `Response closed due to connection limit` exception.
237237

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-
const response = await fetch('https://example.org');
242-
for await (const chunk of resp.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-
const reader = response.body.getReader();
250-
let chunk = await reader.read();
251-
await processChunk(chunk);
252-
chunk = await reader.read();
253-
await processChunk(chunk);
254-
255-
async function processChunk(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-
261238
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()`.
262239

263240
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:
264241

265242
```ts
266-
let resp = await fetch(url);
243+
const response = await fetch(url);
267244

268245
// 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
271248
} else {
272249
// Explicitly cancel it
273-
resp.body.cancel();
250+
response.body.cancel();
274251
}
275252
```
276253

277254
This will free up an open connection.
278255

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.
280259

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
261+
actively read from or written to, for example:
262+
263+
```ts
264+
// Within a for-of loop
265+
const response = await fetch("https://example.org");
266+
for await (const chunk of response.body) {
267+
// While this code block is executing, there are no pending
268+
// reads on the response.body. Accordingly, the system may view
269+
// the stream as not being active within this block.
270+
}
271+
272+
// Using body.getReader()
273+
const response = await fetch("https://example.org");
274+
const reader = response.body.getReader();
275+
let chunk = await reader.read();
276+
await processChunk(chunk);
277+
chunk = await reader.read();
278+
await processChunk(chunk);
279+
280+
async function processChunk(chunk) {
281+
// The stream is considered inactive as there is no pending reads
282+
// on response.body. It may then get cancelled.
283+
}
284+
```
282285

283286
:::note
284287

0 commit comments

Comments
 (0)