Bug Description
When calling txn.scan(range, u32::MAX) within a transaction that has previously deleted entries, the code panics with:
thread 'tokio-runtime-worker' panicked at src/transaction/buffer.rs:133:31:
attempt to add with overflow
Root Cause
In src/transaction/buffer.rs line 133:
let redundant_limit = limit
+ mutation_range
.clone()
.filter(|(_, m)| matches!(m, BufferEntry::Del))
.count() as u32;
When limit = u32::MAX and there are any deleted entries in the buffer, this addition overflows.
Reproduction Steps
- Begin a transaction
- Delete one or more rows
- Within the same transaction, call
scan() with u32::MAX as the limit
- Panic occurs
Example:
let mut txn = client.begin_pessimistic().await?;
txn.delete(key).await?;
let pairs = txn.scan(range, u32::MAX).await?; // PANIC!
Expected Behavior
Using u32::MAX as scan limit (meaning "scan all") should be a valid operation and not cause overflow.
Suggested Fix
Use saturating arithmetic:
let redundant_limit = limit.saturating_add(
mutation_range
.clone()
.filter(|(_, m)| matches!(m, BufferEntry::Del))
.count() as u32
);
Current Workaround
Use i32::MAX as u32 instead of u32::MAX as the scan limit to leave headroom for the addition.
Bug Description
When calling
txn.scan(range, u32::MAX)within a transaction that has previously deleted entries, the code panics with:Root Cause
In
src/transaction/buffer.rsline 133:When
limit = u32::MAXand there are any deleted entries in the buffer, this addition overflows.Reproduction Steps
scan()withu32::MAXas the limitExample:
Expected Behavior
Using
u32::MAXas scan limit (meaning "scan all") should be a valid operation and not cause overflow.Suggested Fix
Use saturating arithmetic:
Current Workaround
Use
i32::MAX as u32instead ofu32::MAXas the scan limit to leave headroom for the addition.