From 7043c68dfbf83620426961a8a2c12c13093a8b73 Mon Sep 17 00:00:00 2001 From: Razz4780 Date: Thu, 2 Jan 2025 14:32:43 +0100 Subject: [PATCH] Fixed handling rejection in intproxy --- .../src/proxies/incoming/subscriptions.rs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mirrord/intproxy/src/proxies/incoming/subscriptions.rs b/mirrord/intproxy/src/proxies/incoming/subscriptions.rs index 8439e79d8e1..990070d0e70 100644 --- a/mirrord/intproxy/src/proxies/incoming/subscriptions.rs +++ b/mirrord/intproxy/src/proxies/incoming/subscriptions.rs @@ -242,6 +242,7 @@ impl SubscriptionsManager { Ok(subscription.confirm()) } + Err(ResponseError::PortAlreadyStolen(port)) => { let Some(subscription) = self.subscriptions.remove(&port) else { return Ok(vec![]); @@ -255,23 +256,26 @@ impl SubscriptionsManager { } } } - Err( - ref response_err @ ResponseError::Forbidden { - blocked_action: BlockedAction::Steal(ref steal_type), - .. - }, - ) => { - tracing::warn!("Port subscribe blocked by policy: {response_err}"); - let Some(subscription) = self.subscriptions.remove(&steal_type.get_port()) else { + + Err(ref response_error @ ResponseError::Forbidden { ref blocked_action, .. }) => { + tracing::warn!(%response_error, "Port subscribe blocked by policy"); + + let port = match blocked_action { + BlockedAction::Steal(steal_type) => steal_type.get_port(), + BlockedAction::Mirror(port) => *port, + }; + let Some(subscription) = self.subscriptions.remove(&port) else { return Ok(vec![]); }; + subscription - .reject(response_err.clone()) - .map_err(|sub|{ - tracing::error!("Subscription {sub:?} was confirmed before, then requested again and blocked by a policy."); - IncomingProxyError::SubscriptionFailed(response_err.clone()) + .reject(response_error.clone()) + .map_err(|subscription|{ + tracing::error!(?subscription, "Subscription was confirmed before, then requested again and blocked by a policy."); + IncomingProxyError::SubscriptionFailed(response_error.clone()) }) } + Err(err) => Err(IncomingProxyError::SubscriptionFailed(err)), } }