From 87af3724f150bdc3ef6a101eeb5a2519af574557 Mon Sep 17 00:00:00 2001 From: Francis Lalonde Date: Wed, 15 Feb 2023 16:45:21 -0500 Subject: [PATCH] Justfile replaces Makefile. Clippy fixes: socket retry exponential backoff calculation --- CHANGES.md | 3 +++ Makefile | 40 ---------------------------------------- justfile | 28 ++++++++++++++++++++++++++++ src/output/socket.rs | 12 ++++++++---- src/scheduler.rs | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) delete mode 100755 Makefile create mode 100755 justfile diff --git a/CHANGES.md b/CHANGES.md index ca996a5..7391af9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,9 @@ - Dropped .travis.yml. Trav's dead, baby. - Revalidated full build after overdue `cargo update` +## version 0.9.1 +- Fix bugs + ## version 0.9.0 - Abandon custom Result type and error module in favor of io::Result usage across all API. (Based on @rtyler's comment in #80) diff --git a/Makefile b/Makefile deleted file mode 100755 index 6090f43..0000000 --- a/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -#!make - -# Why put a makefile in a Cargo project? -# To collect the recipes that require several cargo invocations and / or special flags. -# Maybe I should write a tool for this... - -# SCCACHE can be 'local' or 'off' (default) -# local will cache in ~/.cache/sccache -SCCACHE ?= off -SCCACHE_CMD ?= ~/.cargo/bin/sccache - -CARGO_CMD ?= $(if $(filter off,$(SCCACHE)),,RUSTC_WRAPPER=$(SCCACHE_CMD) )cargo - -# Default target -all: test examples bench - -CARGO_TEST_FLAGS ?= -CARGO_BUILD_FLAGS ?= - -# 'test' is a friendly alias for 'unit_test' -test: - $(CARGO_CMD) test --no-default-features --features="skeptic" - -examples: - $(CARGO_CMD) build --examples - -bench: - $(CARGO_CMD) +nightly bench --features="bench" - -lint: - $(CARGO_CMD) clippy - -clean: - $(CARGO_CMD) clean - -publish: test examples bench lint - cargo publish - -.PHONY: all build clean test examples bench publish - diff --git a/justfile b/justfile new file mode 100755 index 0000000..a36844a --- /dev/null +++ b/justfile @@ -0,0 +1,28 @@ +#!just +# Sane make-like command runner: https://github.com/casey/just + +# Default target +all: format test examples bench lint + +# Unit and doc tests +test: + cargo test --no-default-features --features="skeptic" + +examples: + cargo build --examples + +bench: + cargo +nightly bench --features="bench" + +format: + cargo fmt + +lint: + cargo clippy + +clean: + cargo clean + +# Build all and then publish to crates.io. +publish: all + cargo publish diff --git a/src/output/socket.rs b/src/output/socket.rs index f72deec..84c4052 100755 --- a/src/output/socket.rs +++ b/src/output/socket.rs @@ -31,9 +31,11 @@ impl RetrySocket { // FIXME instead of collecting addresses early, store ToSocketAddrs as trait object // FIXME apparently this can not be one because of Associated Types clusterfuck (?!) let addresses = addresses.to_socket_addrs()?.collect(); + const INIT_DELAY: Duration = Duration::from_millis(MIN_RECONNECT_DELAY_MS); + let next_try = Instant::now().checked_add(INIT_DELAY).expect("init delay"); let mut socket = RetrySocket { retries: 0, - next_try: Instant::now() - Duration::from_millis(MIN_RECONNECT_DELAY_MS), + next_try, addresses, socket: None, }; @@ -63,12 +65,14 @@ impl RetrySocket { fn backoff(&mut self, e: io::Error) -> io::Error { self.socket = None; self.retries += 1; - let delay = MAX_RECONNECT_DELAY_MS.min(MIN_RECONNECT_DELAY_MS << self.retries); + // double the delay with each retry + let exp_delay = MIN_RECONNECT_DELAY_MS << self.retries; + let max_delay = MAX_RECONNECT_DELAY_MS.min(exp_delay); warn!( "Could not connect to {:?} after {} trie(s). Backing off reconnection by {}ms. {}", - self.addresses, self.retries, delay, e + self.addresses, self.retries, exp_delay, e ); - self.next_try = Instant::now() + Duration::from_millis(delay); + self.next_try = Instant::now() + Duration::from_millis(max_delay); e } diff --git a/src/scheduler.rs b/src/scheduler.rs index 0e9c9b8..a1c4c8f 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -143,7 +143,7 @@ impl Scheduler { .spawn(move || { let mut wait_for = MIN_DELAY; while let Some(sss) = sched1.upgrade() { - let &(ref heap_mutex, ref condvar) = &*sss; + let (heap_mutex, condvar) = &*sss; let heap = heap_mutex.lock().unwrap(); let (mut tasks, _timed_out) = condvar.wait_timeout(heap, wait_for).unwrap(); 'work: loop {