Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust sample exits with seg fault #127

Open
syllabix opened this issue Sep 12, 2023 · 6 comments
Open

rust sample exits with seg fault #127

syllabix opened this issue Sep 12, 2023 · 6 comments
Assignees

Comments

@syllabix
Copy link

Hello all! Firstly - thank you for preparing these examples. They have been super useful in understanding how to use the SDK and Ditto end - to - end.

I have been running into an issue trying to get the rust sample to work. I have done the following to generate the error

  1. Configured a playground account on ditto.live
  2. Cloned this project from main
  3. Ran the example project with cargo run --release -- --app-id <app id> --shared-token <playground token> --collection my-collection

The program exits with Segmentation fault: 11

I get the following logs from the Ditto::builder the first time I run the program

[INFO] 2023-09-12T18:26:47.679Z: ; database_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_store"; attachments_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_attachments"; replication_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_replication"; tempfile_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_tempfile"
[DEBUG] 2023-09-12T18:26:48.114Z: AuthClient: Searching Store for CachedSiteInfo
[DEBUG] 2023-09-12T18:26:48.114Z: AuthClient: CACHED_SITE_INFO_KEY not found in storage
[DEBUG] 2023-09-12T18:26:48.114Z: AuthClient: CachedSiteInfo is missing a SiteId, invalidating auth
[DEBUG] 2023-09-12T18:26:48.115Z: AuthClient: CachedSiteInfo is missing a peer key, invalidating auth
[DEBUG] 2023-09-12T18:26:48.115Z: AuthClient: storing to cache; req = SiteInfo
Segmentation fault: 11

When running the program again without cleaning the target dir I get the following repeatedly:

[INFO] 2023-09-12T18:28:45.443Z: ; database_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_store"; attachments_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_attachments"; replication_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_replication"; tempfile_dir = "/Users/syllabix/dittolive/samples/rs/target/release/ditto_tempfile"
[DEBUG] 2023-09-12T18:28:45.887Z: AuthClient: Searching Store for CachedSiteInfo
[DEBUG] 2023-09-12T18:28:45.890Z: AuthClient: found CachedSiteInfo
[INFO] 2023-09-12T18:28:45.890Z: AuthClient: using cached SiteId; site_id = 16906052078113615490
[INFO] 2023-09-12T18:28:45.892Z: AuthClient: no token, authentication needed immediately
[DEBUG] 2023-09-12T18:28:45.893Z: AuthClient: no x509 certificate present
[WARN] 2023-09-12T18:28:45.893Z: AuthClient: No valid Web token present. Cannot request certificate.
Segmentation fault: 11

Development Environment Specs:
Rust Compiler
rustc 1.72.0 (5680fa18f 2023-08-23)

Cargo Dependencies

dittolive-ditto = "=4.1.1"
dittolive-ditto-sys = "=4.1.1"
structopt = "0.3.26"
serde_json = "1.0"

OS
macOS 13.4
x86_64-apple-darwin

( Pardon in advance if this issue is a result of user error 😅 )

@okdistribute
Copy link
Contributor

Can you try again on Ditto 4.4.0?

Thanks for reporting.

@syllabix
Copy link
Author

I moved both ditto and ditto-sys to 4.4.0 but I am still getting the seg faults.

When stepping through with the debugger the crash occurs in the ffi_sdk::ditto_make invocation in builder.rs (line 151)
as this starts to move into unsafe territory - is it possible my compiler configuration is incorrect?

@S4H
Copy link

S4H commented Jan 11, 2024

Hi, tried to get the Rust sample runnnig today and ran into the same issue. I was able to reproduce the issue on both 4.1.1 and 4.5.1 versions of the crate. FWIW the example would not compile without first running a cargo update on the dependencies.

Platform:
M2 Macbook AIr (OSX 14.0) - aarch64-apple-darwin
rustc 1.75.0 (82e1608df 2023-12-21)

With a clean target dir I get the following error:

[VERBOSE] 2024-01-11T16:50:37.515Z: uninitialized_ditto_make, working_dir = "/Users/XXX/coding/ditto-playground/target/debug"
[INFO] 2024-01-11T16:50:37.515Z: database_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_store"; attachments_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_attachments"; replication_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_replication"; tempfile_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_tempfile"; logs_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_logs"
[VERBOSE] 2024-01-11T16:50:37.516Z: registering event source with poller: token=Token(1), interests=READABLE; log.target = "mio::poll"; log.module_path = "mio::poll"; log.file = "/Users/ci/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.8/src/poll.rs"; log.line = 531
[DEBUG] 2024-01-11T16:50:37.727Z: AuthClient: Searching Store for CachedSiteInfo
[DEBUG] 2024-01-11T16:50:37.727Z: AuthClient: CACHED_SITE_INFO_KEY not found in storage
[DEBUG] 2024-01-11T16:50:37.727Z: AuthClient: CachedSiteInfo is missing a SiteId, invalidating auth
[DEBUG] 2024-01-11T16:50:37.727Z: AuthClient: CachedSiteInfo is missing a peer key, invalidating auth
[DEBUG] 2024-01-11T16:50:37.727Z: AuthClient: storing to cache; req = SiteInfo
[VERBOSE] 2024-01-11T16:50:37.728Z: registering event source with poller: token=Token(1), interests=READABLE; log.target = "mio::poll"; log.module_path = "mio::poll"; log.file = "/Users/ci/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.8/src/poll.rs"; log.line = 531
[1]    92857 segmentation fault  cargo +nightly run

On subsequent runs, I get the following failure

[VERBOSE] 2024-01-11T16:53:09.435Z: uninitialized_ditto_make, working_dir = "/Users/XXX/coding/ditto-playground/target/debug"
[INFO] 2024-01-11T16:53:09.436Z: database_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_store"; attachments_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_attachments"; replication_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_replication"; tempfile_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_tempfile"; logs_dir = "/Users/XXX/coding/ditto-playground/target/debug/ditto_logs"
[VERBOSE] 2024-01-11T16:53:09.436Z: registering event source with poller: token=Token(1), interests=READABLE; log.target = "mio::poll"; log.module_path = "mio::poll"; log.file = "/Users/ci/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.8/src/poll.rs"; log.line = 531
[DEBUG] 2024-01-11T16:53:09.648Z: AuthClient: Searching Store for CachedSiteInfo
[DEBUG] 2024-01-11T16:53:09.648Z: AuthClient: found CachedSiteInfo
[INFO] 2024-01-11T16:53:09.648Z: AuthClient: using cached SiteId; site_id = 7626723754741463250
[INFO] 2024-01-11T16:53:09.649Z: AuthClient: no token, authentication needed immediately
[VERBOSE] 2024-01-11T16:53:09.649Z: task started[VERBOSE] 2024-01-11T16:53:09.649Z: task started; task_name = "AuthClient x509 Watcher"
; task_name = "AuthClient refresh"
[DEBUG] 2024-01-11T16:53:09.649Z: AuthClient: no x509 certificate present
[WARN] 2024-01-11T16:53:09.649Z: AuthClient: No valid Web token present. Cannot request certificate.
[WARN] 2024-01-11T16:53:09.649Z: AuthClient: failed to obtain a certificate ValueNotFound
[1]    93223 bus error  cargo +nightly run

@okdistribute
Copy link
Contributor

Sorry you ran into this. Can you try Rust version 1.66.1?

@S4H
Copy link

S4H commented Jan 12, 2024

Sorry you ran into this. Can you try Rust version 1.66.1?

Success. rustc 1.66.1 works with both 4.1.1 and 4.4.0 versions of the SDK (4.5.1 fails to compile however due to ahash attempting to use stdsimd).

@okdistribute
Copy link
Contributor

Thanks, @S4H, for reporting back. Ditto currently requires using a particular rust version and we are working on remedying this in the future with an ffi mangling layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants