Skip to content

Commit e5fa422

Browse files
ldanilekConvex, Inc.
authored andcommitted
error on pagination edge cases (#26190)
if you do the following in a UDF, you can cause a system error loop with an error message about the cursor not being set. ``` await ctx.db.query("messages").paginate({ ...args.paginationOpts, maximumRowsRead: 0, // or maximumBytesRead: 0, } as PaginationOptions); ``` fix this by catching the zero case early. and also detect when we hit a pagination limit before setting the cursor. this should never happen, because in order to hit a pagination limit you need to have fetched some data, and if you fetched data then you must have set the cursor. if the scenario ever does happen, we can log the pagination error, which should help narrow down what's going on. GitOrigin-RevId: 491bceae908bce0c6812378e3c160de3c303983d
1 parent 9cc114c commit e5fa422

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/isolate/src/environment/udf/async_syscall.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,14 @@ impl<RT: Runtime, P: AsyncSyscallProvider<RT>> DatabaseSyscallsShared<RT, P> {
10061006
Err(e) => {
10071007
if e.is_pagination_limit() {
10081008
page_status = Some(QueryPageStatus::SplitRequired);
1009+
if query.cursor().is_none() {
1010+
// Intentionally drop ErrorMetadata because this should
1011+
// be impossible, so we want to throw a system error instead.
1012+
anyhow::bail!(
1013+
"This should be impossible. Hit pagination limit before setting \
1014+
query cursor: {e:?}"
1015+
);
1016+
}
10091017
break;
10101018
}
10111019
anyhow::bail!(e);
@@ -1060,6 +1068,12 @@ impl<RT: Runtime, P: AsyncSyscallProvider<RT>> DatabaseSyscallsShared<RT, P> {
10601068
"Must request at least 1 document while paginating"
10611069
));
10621070
}
1071+
if args.maximum_rows_read == Some(0) || args.maximum_bytes_read == Some(0) {
1072+
anyhow::bail!(ErrorMetadata::bad_request(
1073+
"InvalidPaginationLimit",
1074+
"maximumRowsRead and maximumBytesRead must be greater than 0"
1075+
));
1076+
}
10631077

10641078
let start_cursor = args
10651079
.cursor

0 commit comments

Comments
 (0)