Skip to content

Commit 6d309ea

Browse files
committed
set state to reconnecting earlier
Signed-off-by: Marc-Antoine Perennou <[email protected]>
1 parent 21c782a commit 6d309ea

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/channel.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -565,28 +565,25 @@ impl Channel {
565565
}
566566

567567
fn next_expected_close_ok_reply(&self) -> Option<Reply> {
568-
self.frames
569-
.next_expected_close_ok_reply(self.id, Error::InvalidChannelState(ChannelState::Closed, None))
568+
self.frames.next_expected_close_ok_reply(
569+
self.id,
570+
Error::InvalidChannelState(ChannelState::Closed, None),
571+
)
570572
}
571573

572574
fn before_channel_close(&self) {
573575
self.set_closing(None);
574576
}
575577

576578
fn on_channel_close_ok_sent(&self, error: Option<Error>) {
577-
match (self.recovery_config.auto_recover_channels, error) {
578-
(true, Some(error)) if error.is_amqp_soft_error() => {
579-
self.status.set_reconnecting(error)
580-
}
581-
(_, error) => {
582-
self.set_closed(
583-
error
584-
.clone()
585-
.unwrap_or(Error::InvalidChannelState(ChannelState::Closing, None)),
586-
);
587-
if let Some(error) = error {
588-
self.error_handler.on_error(error);
589-
}
579+
if !self.recovery_config.auto_recover_channels || !error.as_ref().map_or(false, Error::is_amqp_soft_error) {
580+
self.set_closed(
581+
error
582+
.clone()
583+
.unwrap_or(Error::InvalidChannelState(ChannelState::Closing, None)),
584+
);
585+
if let Some(error) = error {
586+
self.error_handler.on_error(error);
590587
}
591588
}
592589
}
@@ -916,7 +913,12 @@ impl Channel {
916913
);
917914
Error::ProtocolError(error)
918915
});
919-
self.set_closing(error.clone().ok());
916+
match (self.recovery_config.auto_recover_channels, error.clone().ok()) {
917+
(true, Some(error)) if error.is_amqp_soft_error() => {
918+
self.status.set_reconnecting(error)
919+
}
920+
(_, err) => self.set_closing(err),
921+
}
920922
let error = error.map_err(|error| info!(channel=%self.id, ?method, code_to_error=%error, "Channel closed with a non-error code")).ok();
921923
let channel = self.clone();
922924
self.internal_rpc.register_internal_future(async move {

src/channel_status.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ impl ChannelStatus {
1818
}
1919

2020
pub fn closing(&self) -> bool {
21-
self.0.lock().state == ChannelState::Closing
21+
[ChannelState::Closing, ChannelState::Reconnecting].contains(&self.0.lock().state)
2222
}
2323

2424
pub fn connected(&self) -> bool {
2525
self.0.lock().state == ChannelState::Connected
2626
}
2727

28+
pub fn reconnecting(&self) -> bool {
29+
self.0.lock().state == ChannelState::Reconnecting
30+
}
31+
2832
pub(crate) fn connected_or_recovering(&self) -> bool {
2933
[ChannelState::Connected, ChannelState::Reconnecting].contains(&self.0.lock().state)
3034
}

0 commit comments

Comments
 (0)