fdb-rs / fdb

FoundationDB client API for Tokio
https://fdb-rs.github.io/
Apache License 2.0
43 stars 2 forks source link

misaligned pointer dereference with rust 1.70 #33

Open ggilley opened 1 year ago

ggilley commented 1 year ago

Looks like rust made a change in 1.70 to throw on misaligned pointer dereferences. I'm seeing some errors:

stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_misaligned_pointer_dereference
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:174:5
   3: <fdb::range::KeyValueArray as fdb::future::FdbFutureGet>::get::{{closure}}::{{closure}}
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/future.rs:413:21
   4: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/traits/iterator.rs:854:29
   5: core::iter::traits::iterator::Iterator::fold
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/traits/iterator.rs:2482:21
   6: core::iter::traits::iterator::Iterator::for_each
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/traits/iterator.rs:857:9
   7: <fdb::range::KeyValueArray as fdb::future::FdbFutureGet>::get::{{closure}}
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/future.rs:409:13
   8: core::result::Result<T,E>::map
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:759:25
   9: <fdb::range::KeyValueArray as fdb::future::FdbFutureGet>::get
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/future.rs:400:9
  10: <fdb::future::FdbFuture<T> as core::future::future::Future>::poll
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/future.rs:172:34
  11: fdb::range::RangeResultStateMachine::poll_next
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/range.rs:358:31
  12: <fdb::future::FdbStreamKeyValue as futures_core::stream::Stream>::poll_next
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/future.rs:588:9
  13: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/mod.rs:1632:9
  14: <futures_util::stream::stream::next::Next<St> as core::future::future::Future>::poll
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/next.rs:32:9
  15: <fdblib::directory::FDBDriver as fdblib::directory::Database>::get_project_keys::{{closure}}::{{closure}}::{{closure}}
             at ./src/directory.rs:1259:46
  16: fdb::database::fdb_database::FdbDatabase::read::{{closure}}
             at /Users/ggilley/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fdb-0.3.1/src/database/fdb_database.rs:258:39
rajivr commented 1 year ago

Can you please try applying the changes that is currently here

https://github.com/rajivr/fdb-wip/commit/3a07b55bd0215b42bf3b27cae9e94ab28e9e767c

https://github.com/rajivr/fdb-wip/commit/6fd4c2a006c47e802c14b41baf38ad41ca4e59a5

And let me know if it works for you!

If you are comfortable, using bleeding edge repository, I would recommend switching over and vendoring fdb-wip.

I am using it for my own Record Layer development (which you can see here)

ggilley commented 1 year ago

That works. Thanks! I'll try fdb-wip next.

ggilley commented 1 year ago

I was able to get fdb-wip to work. I created a PR to fix fdb in case anyone else runs into the issue. Thanks!

rajivr commented 1 year ago

Thanks @ggilley for the PR and sorry for the delay in responding to it. I will shortly review, merge and do a new release of the crate. In the meantime feel free to use APIs (and code) from fdb-rl-wip crate. It has a lot of good APIs that might be useful for your own layer development.