Skip to content

Commit

Permalink
Fixed panic when trying to reuse disconnected socket for ping
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-meissner committed May 21, 2022
1 parent 193998d commit de586ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keywords = ["redis", "network", "no_std", "database"]
categories = ["embedded", "database", "no-std"]
authors = ["PEGASUS GmbH <[email protected]>"]
license = "MIT OR Apache-2.0"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
repository = "https://github.com/pegasus-aero/rt-embedded-redis"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/network/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ where
}

if !network.is_connected(self.socket.as_ref().unwrap()).unwrap_or(false) {
self.disconnect(network);
return self.disconnect(network);
}

if self.use_ping && self.ping(network, clock).is_err() {
Expand Down
22 changes: 21 additions & 1 deletion src/network/tests/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn test_connect_socket_ping_successful() {
}

#[test]
fn test_connect_cached_socket_not_connected() {
fn test_connect_cached_socket_not_connected_without_ping() {
let clock = TestClock::new(vec![]);

let mut stack = NetworkMockBuilder::default()
Expand All @@ -351,3 +351,23 @@ fn test_connect_cached_socket_not_connected() {
handler.connect(&mut stack, Some(&clock)).unwrap();
handler.connect(&mut stack, Some(&clock)).unwrap();
}

#[test]
fn test_connect_cached_socket_not_connected_with_ping() {
let clock = TestClock::new(vec![]);

let mut stack = NetworkMockBuilder::default()
.socket(167)
.connect(167)
.expect_is_connected(167, false)
.close(167)
.socket(297)
.connect(297)
.into_mock();

let mut handler = ConnectionHandler::resp2(SocketAddr::from_str("127.0.0.1:6379").unwrap());
handler.use_ping();

handler.connect(&mut stack, Some(&clock)).unwrap();
handler.connect(&mut stack, Some(&clock)).unwrap();
}

0 comments on commit de586ad

Please sign in to comment.