Skip to content

Commit 0fcd3ef

Browse files
committed
fixup!
1 parent 5c4bab7 commit 0fcd3ef

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -235,50 +235,54 @@ 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+
{
268+
// While this code block is executing, there are no pending
269+
// reads on the response.body. Accordingly, the system may view
270+
// the stream as not being active within this block.
271+
}
272+
273+
// Using body.getReader()
274+
const response = await fetch('https://example.org');
275+
const reader = response.body.getReader();
276+
let chunk = await reader.read();
277+
await processChunk(chunk);
278+
chunk = await reader.read();
279+
await processChunk(chunk);
280+
281+
async function processChunk(chunk) {
282+
// The stream is considered inactive as there is no pending reads
283+
// on response.body. It may then get cancelled.
284+
}
285+
```
282286

283287
:::note
284288

@@ -305,7 +309,7 @@ You can assess the size of your Worker bundle after compression by performing a
305309

306310
```sh
307311
wrangler deploy --outdir bundled/ --dry-run
308-
```
312+
````
309313

310314
```sh output
311315
# Output will resemble the below:

0 commit comments

Comments
 (0)