Skip to content

Instantly share code, notes, and snippets.

@Fyko
Last active October 21, 2023 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fyko/cdaa113505dcca334372b18896381266 to your computer and use it in GitHub Desktop.
Save Fyko/cdaa113505dcca334372b18896381266 to your computer and use it in GitHub Desktop.
meilisearch sdk panic reproducable example

Meilisearch Panic

This is a reproducable example of streaming a file using meilisearch's new CSV features.

Reproducable steps

  1. Clone this gist
$ git clone git@gist.github.com:cdaa113505dcca334372b18896381266.git meili-panic
$ cd meili-panic
  1. Start meilisearch with docker compose up --wait
  2. Run the program cargo run --release
  3. Observe errors

Error

  2023-10-20T23:36:48.526475Z DEBUG isahc::agent: agent took 77.397µs to start up
    at /home/carter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/isahc-1.7.2/src/agent/mod.rs:125 on isahc-agent-0
    in isahc::agent::agent_thread with id: 0

  2023-10-20T23:36:48.526603Z DEBUG isahc::handler:   Trying [::1]:7700...
    at /home/carter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/isahc-1.7.2/src/handler.rs:653 on isahc-agent-0
    in isahc::handler::handler with id: 0
    in isahc::client::send_async with method: POST, uri: http://localhost:7700/indexes/testing/documents?primaryKey=id

  2023-10-20T23:36:48.526682Z DEBUG isahc::handler: Connected to localhost (::1) port 7700
    at /home/carter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/isahc-1.7.2/src/handler.rs:653 on isahc-agent-0
    in isahc::handler::handler with id: 0
    in isahc::client::send_async with method: POST, uri: http://localhost:7700/indexes/testing/documents?primaryKey=id

thread 'isahc-agent-0' panicked at /home/carter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/fs/file.rs:545:47:
there is no reactor running, must be called from the context of a Tokio 1.x runtime
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  2023-10-20T23:36:48.527777Z ERROR isahc::agent: agent shut down with error: Error { kind: Unknown, context: None, source: Some(MultiError { description: "Operation was aborted by an application callback", code: 11 }), source_type: Some("curl::error::MultiError"), local_addr: None, remote_addr: None }
    at /home/carter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/isahc-1.7.2/src/agent/mod.rs:130 on isahc-agent-0
    in isahc::agent::agent_thread with id: 0

Error: HTTP request failed: unknown error

Meilisearch Debug Logs

[2023-10-20T23:38:01Z DEBUG meilisearch::routes::indexes::documents] called with params: AwebQueryParameter(UpdateDocumentsQuery { primary_key: Some("id"), csv_delimiter: None }, PhantomData<*const meilisearch_types::deserr::DeserrError<meilisearch_types::deserr::DeserrQueryParam, meilisearch_types::error::deserr_codes::BadRequest>>)
[2023-10-20T23:38:01Z DEBUG actix_web::middleware::logger] Error in response: ResponseError { code: 400, message: "A csv payload is missing.", error_code: "missing_payload", error_type: "invalid_request", error_link: "https://docs.meilisearch.com/errors#missing_payload" }
[2023-10-20T23:38:01Z INFO  actix_web::middleware::logger] 172.21.0.1 "POST /indexes/testing/documents?primaryKey=id HTTP/1.1" 400 150 "-" "Meilisearch Rust (v0.24.2)" 0.000790
[package]
name = "meili-panic"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "meili-panic"
path = "main.rs"
[dependencies]
anyhow = "1"
futures = "0.3"
meilisearch-sdk = { version = "0.24", default-features = false }
tokio = { version = "1", features = [
"macros",
"rt-multi-thread",
"io-util",
"fs",
] }
tokio-util = { version = "0.7", features = ["compat"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [
"fmt",
"env-filter",
"json",
] }
version: '3.9'
services:
meilisearch:
image: getmeili/meilisearch
restart: unless-stopped
volumes:
- ./meilisearch-data:/data.ms
environment:
MEILI_DB_PATH: /data.ms
MEILI_LOG_LEVEL: debug
healthcheck:
test: ["CMD", "curl", "-s", "http://meilisearch:7700/health"]
retries: 10
interval: 15s
timeout: 5s
ports:
- '7700:7700'
use anyhow::Result;
use meilisearch_sdk::Client as MeiliClient;
use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
#[tokio::main]
async fn main() -> Result<()> {
Registry::default()
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| "debug".into()))
.with(
fmt::layer()
.pretty()
.with_thread_names(true)
.with_line_number(true)
.with_file(true),
)
.init();
let client = MeiliClient::new("http://localhost:7700", None::<&str>);
let crates_index = client.index("testing");
let file = tokio::fs::File::open(format!("{}/test.csv", env!("CARGO_MANIFEST_DIR"))).await?;
use tokio_util::compat::TokioAsyncReadCompatExt;
let file = file.compat();
let task = crates_index.add_documents_csv(file, Some("id")).await?;
client.wait_for_task(task, None, None).await?;
Ok(())
}
id:number name:string
1 Fyko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment