Skip to content

Commit

Permalink
Idempotent UNSUB avoids sending multiple UNSUB messages when subscrip…
Browse files Browse the repository at this point in the history
…tions are dropped or manually unsubscribed.
  • Loading branch information
spacejam committed May 19, 2021
1 parent 9b97c1a commit 06bc375
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Improvements

- #180 idempotent unsubscription avoids sending
multiple UNSUB messages.

# 0.9.16

## Improvements

- #178 client state has been reorganized to allow
reading and writing to make progress independently,
preventing issues that were sometimes encountered
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nats"
version = "0.9.16"
version = "0.9.17"
description = "A Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand Down
4 changes: 2 additions & 2 deletions async-nats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-nats"
version = "0.9.16"
version = "0.9.17"
description = "An async Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand All @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
blocking = "1.0.2"
nats = { path = "..", version = "0.9.16" }
nats = { path = "..", version = "0.9.17" }

[dev-dependencies]
smol = "1.2.5"
Expand Down
10 changes: 9 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ impl Client {
let mut read = self.state.read.lock();

// Remove the subscription from the map.
read.subscriptions.remove(&sid);
if read.subscriptions.remove(&sid).is_none() {
// already unsubscribed

// NB see locking protocol for state.write and state.read
drop(read);
drop(write);

return Ok(());
}

// Send an UNSUB message.
if let Some(writer) = write.writer.as_mut() {
Expand Down

0 comments on commit 06bc375

Please sign in to comment.