capsule-rs / capsule-rs/capsule
panic/unreachable from udp.data function in benchmarks using udp4 proptest strategy
- Dominant language
- Rust
- Stars
- 443
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
## Describe the bug?
Using the `udp4` proptest strategy to generate UDP4 packets in bench mark test, I noticed when making a call to that packet's `data()` function I'd get an unreachable panic. In adding some instrumentation, it is panicking because the payload_offset is 42 and the data buffer length itself is also 42. I did notice in adding println to the function that the issue would go away (memory/concurrency issue maybe?). I don't see it with my own strategy that uses the udp4 call but then extends the packet with a payload, which is doesn't have in the proptest generation. But then the payload may be masking it. Will know if that's true with some more testing.
I made a [slight change](https://github.com/sbuzzard/capsule/blob/topic/data-offset-err-with-udp4-strategy/core/src/packets/udp.rs#L153-L164) to udp4 in the `data()` function as part of this repoduction to get the specific error.
## Steps to reproduce?
[this branch in my fork](https://github.com/sbuzzard/capsule/blob/topic/data-offset-err-with-udp4-strategy) demonstrates it with [this change](https://github.com/sbuzzard/capsule/blob/topic/data-offset-err-with-udp4-strategy/bench/packets.rs#L37)
### Capsule version?
I am using the `djin/borrow-mut-parse` branch (0.0.2 pre-alpha) - my branch above was made from that.
### OS?
Using the capsule sandbox
### Docker / VM / Bare?
Using the capsule sandbox with vagrant but not with the docker image in vagrant.
### Stack trace or error log output
```
Benchmarking packets::single_peek_vs_parse_on_udp/packets::single_parse_udp: Warming up for 3.0000 sError in data buffer: Offset 42 exceeds the buffer length 42.
thread 'main' panicked at 'internal error: entered unreachable code', /opt/sources/dpdk/capsule/capsule/core/src/packets/udp.rs:161:17
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::panicking::panic
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:48:5
3: as core::iter::traits::iterator::Iterator>::fold
4: criterion::bencher::Bencher::iter_custom
5: as criterion::routine::Routine>::warm_up
6: criterion::routine::Routine::sample
7: criterion::analysis::common
8: criterion::benchmark_group::BenchmarkGroup::bench_function
9: packets::main
```
Contributor guide
Research direction
Start with core/src/packets/udp.rs around the udp4 data() implementation and compare it with the reproduction change linked in the issue. Run the benchmark in bench/packets.rs using the udp4 proptest strategy, then check the payload_offset and data-buffer behavior shown by the stack trace. Done means the benchmark no longer reaches the unreachable panic for generated UDP4 packets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100