Skip to content

Commit 6ede51f

Browse files
emmaling27Convex, Inc.
authored andcommitted
Make node actions args limit user error (#38319)
AWS Lambda has a 6MiB limit on request size. This PR adds a check that arguments don't exceed 5MiB and makes it a user error instead of an internal server error. GitOrigin-RevId: b7f14275a160e04c7b391bb64c582846157db4c5
1 parent 59cc33a commit 6ede51f

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

crates/node_executor/src/executor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ pub fn error_response_json(message: &str) -> JsonValue {
120120
})
121121
}
122122

123+
// AWS Lambda has a 6MiB limit on invoke request size,
124+
// and we leave some headroom for other data in `ExecuteRequest` like
125+
// environment variables which could take up to 100 * 8KiB = 800 KiB
126+
const NODE_ACTIONS_ARGS_SIZE_LIMIT: usize = 5 * 1024 * 1024; // 5MiB
127+
123128
pub static EXECUTE_TIMEOUT_RESPONSE_JSON: LazyLock<JsonValue> = LazyLock::new(|| {
124129
error_response_json(
125130
"Function execution unexpectedly timed out. Check your function for infinite loops or \
@@ -230,6 +235,7 @@ impl<RT: Runtime> Actions<RT> {
230235
+ Send,
231236
) -> anyhow::Result<NodeActionOutcome> {
232237
let path = request.path_and_args.path().clone();
238+
anyhow::ensure!(request.path_and_args.args_size() < NODE_ACTIONS_ARGS_SIZE_LIMIT, ErrorMetadata::bad_request("ArgsTooLarge", format!("Node actions arguments size is too large: {} bytes. The maximum size is {} bytes.", request.path_and_args.args_size(), NODE_ACTIONS_ARGS_SIZE_LIMIT)));
233239
let timer = node_executor("execute");
234240
let request = ExecutorRequest::Execute {
235241
request,

crates/udf/src/validation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ impl ValidatedPathAndArgs {
505505
}))
506506
}
507507

508+
pub fn args_size(&self) -> usize {
509+
self.args.heap_size()
510+
}
511+
508512
#[cfg(any(test, feature = "testing"))]
509513
pub fn new_for_tests(
510514
udf_path: CanonicalizedUdfPath,

npm-packages/docs/docs/functions/runtimes.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,5 @@ without the `"use node"` directive should not import any files with the
156156
`"use node"` directive. Files that contain no Convex functions, like a
157157
`convex/utils.ts` file, also need the "use node" directive if they use
158158
Node.js-specific libraries.
159+
160+
Note that argument size limits are lower (5MiB instead of 16MiB).

npm-packages/docs/docs/production/state/limits.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Applied per document and to any nested `Object` unless stated otherwise.
6262
| Function calls | 1,000,000/month included<br/>(on Starter: $2.20 per additional 1,000,000) | 25,000,000/month included<br/>$2 per additional 1,000,000 | Explicit client calls, scheduled executions, subscription updates, and file accesses count as function calls. |
6363
| Action execution | 20 GiB-hours included<br/>(on Starter: $0.33/GiB-hour additional) | 250 GiB-hours included<br/>$0.30/GiB-hour additional | Convex runtime: 64 MiB RAM.<br/>Node.js runtime: 512 MiB RAM. |
6464
| Code size | 32 MiB | 32 MiB | Per deployment. |
65-
| Function argument size | 16 MiB | 16 MiB | |
65+
| Function argument size | 16 MiB | 16 MiB | Node actions only support arguments up to 5MiB. |
6666
| Function return value size | 16 MiB | 16 MiB | |
6767
| HTTP action response size | 20 MiB | 20 MiB | There is no specific limit on request size |
6868
| Length of a console.log line | 4 KiB | 4 KiB | |

0 commit comments

Comments
 (0)