{"record":{"id":"0cc9b14fae417e33","repo":"withastro/astro","slug":"body-size-limit-exceeded-received-more-than-lim","errorCode":null,"errorMessage":"Body size limit exceeded: received more than ${limit} bytes","messagePattern":"Body size limit exceeded: received more than (.+?) bytes","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/app/node.ts","lineNumber":487,"sourceCode":"/**\n * Wraps an async iterable with a size limit. If the total bytes received\n * exceed the limit, an error is thrown.\n */\nasync function* limitAsyncIterable(\n\titerable: AsyncIterable<any>,\n\tlimit: number,\n): AsyncGenerator<any> {\n\tlet received = 0;\n\tfor await (const chunk of iterable) {\n\t\tconst byteLength =\n\t\t\tchunk instanceof Uint8Array\n\t\t\t\t? chunk.byteLength\n\t\t\t\t: typeof chunk === 'string'\n\t\t\t\t\t? Buffer.byteLength(chunk)\n\t\t\t\t\t: 0;\n\t\treceived += byteLength;\n\t\tif (received > limit) {\n\t\t\tthrow new Error(`Body size limit exceeded: received more than ${limit} bytes`);\n\t\t}\n\t\tyield chunk;\n\t}\n}\n\n/**\n * Returns the cleanup function for the AbortController and socket listeners created by `createRequest()`\n * for the NodeJS IncomingMessage. This should only be called directly if the request is not\n * being handled by Astro, i.e. if not calling `writeResponse()` after `createRequest()`.\n * ```js\n * import { createRequest, getAbortControllerCleanup } from 'astro/app/node';\n * import { createServer } from 'node:http';\n *\n * const server = createServer(async (req, res) => {\n *     const request = createRequest(req);\n *     const cleanup = getAbortControllerCleanup(req);\n *     if (cleanup) cleanup();\n *     // can now safely call another handler","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/app/node.ts#L469-L505","documentation":"Thrown by the Node adapter's `limitAsyncIterable` wrapper when the total bytes received from the request body stream exceed the configured limit. The function accumulates `received` across all chunks; once it surpasses `limit`, a plain `Error` is thrown (not an AstroError) with the limit in bytes. This is a DoS protection mechanism for the Node app server.","triggerScenarios":"A client sends a POST/PUT request whose body (form data, JSON payload, file upload) exceeds the byte limit configured for the Node adapter. The `limitAsyncIterable` generator is wrapping the request's async iterable body, and the cumulative byte count crosses the threshold.","commonSituations":"Uploading a large file via a form POST. Sending a very large JSON body to an API endpoint. The body size limit is set too low for the application's needs. A client accidentally sends an unbounded stream. Testing with large payloads against a locally running Node adapter.","solutions":["Increase the body size limit in your Node adapter/standalone server configuration.","If using `@astrojs/node`, check the adapter's request body limit settings.","Split large uploads into chunks or use a dedicated file upload endpoint.","Compress the request body (gzip/brotli) if the client supports it.","Validate expected payload size on the client before sending."],"exampleFix":"// before — default limit too small for file uploads\nimport { createHandler } from 'astro/app/node';\n\n// after — configure a higher limit\n// In standalone server or custom handler setup, increase the body limit:\n// Pass a larger `limit` to the request body reader or configure\n// the adapter to accept larger payloads per your server framework docs.","handlingStrategy":"validation","validationCode":"function assertBodySize(contentLength: string | null, limit: number) {\n  if (contentLength && parseInt(contentLength, 10) > limit) {\n    throw new Error(`Request body exceeds ${limit} bytes`);\n  }\n}","typeGuard":null,"tryCatchPattern":"app.post('/upload', async (req, res) => {\n  try {\n    await readBody(req);\n  } catch (e) {\n    if (e instanceof Error && e.message.includes('Body size limit exceeded')) {\n      res.status(413).json({ error: 'Payload too large' });\n      return;\n    }\n    throw e;\n  }\n});","preventionTips":["Set body size limits appropriate for your endpoints.","Check Content-Length header before reading the body.","Use streaming uploads for large files instead of buffering.","Return 413 status to clients on body limit errors."],"tags":["node-adapter","request-body","dos-protection","limits","ssr"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}