diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb2e108..3a1df477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ +# v0.12.3 + +## Changed + +- Retry conflicts as a workaround for comment creation / updates generating + spurious conflicts. We will be fixing this properly in the backend, but as a + workaround we will retry conflicts for now. + # v0.12.2 + - Rename "triggers" to "streams" following the rename in the API - Removed semantic url joins to support deployments within a subdirectory - Added functionality to use moon forms both in `LabelDef`s and in `AnnotatedComments`s diff --git a/Cargo.lock b/Cargo.lock index da08346e..3c852356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,7 +1198,7 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "reinfer-cli" -version = "0.12.2" +version = "0.12.3" dependencies = [ "anyhow", "chrono", @@ -1223,7 +1223,7 @@ dependencies = [ [[package]] name = "reinfer-client" -version = "0.12.2" +version = "0.12.3" dependencies = [ "chrono", "log", diff --git a/README.md b/README.md index c6377bd3..b1360328 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ The [api](/api) directory contains a Rust client library for reinfer which can b Statically linked binaries with no dependencies are provided for selected platforms: -- [Linux (x86_64-unknown-linux-musl)](https://reinfer.io/public/cli/bin/x86_64-unknown-linux-musl/0.12.2/re) -- [macOS (x86_64-apple-darwin)](https://reinfer.io/public/cli/bin/x86_64-apple-darwin/0.12.2/re) -- [Windows (x86_64-pc-windows-gnu)](https://reinfer.io/public/cli/bin/x86_64-pc-windows-gnu/0.12.2/re.exe) +- [Linux (x86_64-unknown-linux-musl)](https://reinfer.io/public/cli/bin/x86_64-unknown-linux-musl/0.12.3/re) +- [macOS (x86_64-apple-darwin)](https://reinfer.io/public/cli/bin/x86_64-apple-darwin/0.12.3/re) +- [Windows (x86_64-pc-windows-gnu)](https://reinfer.io/public/cli/bin/x86_64-pc-windows-gnu/0.12.3/re.exe) ### Debian / Ubuntu -You can download a `.deb` package [here](https://reinfer.io/public/cli/debian/reinfer-cli_0.12.2_amd64.deb). +You can download a `.deb` package [here](https://reinfer.io/public/cli/debian/reinfer-cli_0.12.3_amd64.deb). ### From Source diff --git a/api/Cargo.toml b/api/Cargo.toml index 39a4a2bb..2e7da50a 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reinfer-client" -version = "0.12.2" +version = "0.12.3" description = "API client for Re:infer, the conversational data intelligence platform" homepage = "https://github.com/reinfer/cli" readme = "README.md" diff --git a/api/src/retry.rs b/api/src/retry.rs index f29ff7d6..51f87d8a 100644 --- a/api/src/retry.rs +++ b/api/src/retry.rs @@ -1,7 +1,9 @@ -use reqwest::{blocking::Response, Result}; -use std::sync::atomic::{AtomicBool, Ordering::SeqCst}; -use std::thread::sleep; -use std::time::Duration; +use reqwest::{blocking::Response, Result, StatusCode}; +use std::{ + sync::atomic::{AtomicBool, Ordering::SeqCst}, + thread::sleep, + time::Duration, +}; /// Strategy to use if retrying . #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -60,7 +62,7 @@ impl Retrier { } match send_request() { - Ok(response) if response.status().is_server_error() => { + Ok(response) if should_retry(&response) => { warn_and_sleep!(format!("{} for {}", response.status(), response.url())) } Err(error) if error.is_timeout() => warn_and_sleep!(error), @@ -74,6 +76,14 @@ impl Retrier { } } +fn should_retry(response: &Response) -> bool { + // TODO(mcobzarenco): we retry conflicts as a workaround for comment + // creation / updates conflicting with the `loom` service that indexes + // threads objects concurrently. We will be fixing this properly in the + // backend, but as a workaround we will retry conflicts for now. + response.status().is_server_error() || response.status() == StatusCode::CONFLICT +} + #[cfg(test)] mod tests { use super::{Retrier, RetryConfig, RetryStrategy}; @@ -201,4 +211,37 @@ mod tests { .is_timeout()); timeout.assert(); } + + #[test] + fn test_retry_conflicts() { + // TODO(mcobzarenco): we retry conflicts as a workaround for comment + // creation / updates conflicting with the `loom` service that indexes + // threads objects concurrently. We will be fixing this properly in the + // backend, but as a workaround we will retry conflicts for now. + + let mut handler = Retrier::new(RetryConfig { + strategy: RetryStrategy::Always, + max_retry_count: 5, + base_wait: Duration::from_secs(0), + backoff_factor: 0.0, + }); + let client = Client::builder().build().unwrap(); + + // Retries up to N times on timeout for non-first-requests. + for i_retry in 0..10 { + let err = mock("POST", "/") + .with_status(409) + .expect((i_retry + 1).into()) + .create(); + handler.config.max_retry_count = i_retry; + assert_eq!( + handler + .with_retries(|| client.post(format!("http://{}", server_address())).send()) + .unwrap() + .status(), + 409 + ); + err.assert(); + } + } } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c09b39e0..8a686643 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reinfer-cli" -version = "0.12.2" +version = "0.12.3" description = "Command line interface for Re:infer, the conversational data intelligence platform" homepage = "https://github.com/reinfer/cli" readme = "README.md" @@ -34,7 +34,7 @@ serde_json = "1.0.87" structopt = { version = "0.3.26", default-features = false } url = { version = "2.3.1", features = ["serde"] } -reinfer-client = { version = "0.12.2", path = "../api" } +reinfer-client = { version = "0.12.3", path = "../api" } [dev-dependencies] pretty_assertions = "1.3.0"