Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control_plane_agent: detach stale faux-mgs clients on new attach requests #1925

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions task/control-plane-agent/src/mgs_compute_sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ impl MgsHandler {
id
}

fn get_attached_nonidle_client(
&mut self,
) -> &Option<AttachedSerialConsoleMgs> {
if let Some(attached) = &self.attached_serial_console_mgs {
// Check whether we think this client has disappeared
let client_age_ms = sys_get_timer()
.now
.saturating_sub(attached.last_keepalive_received);
if Duration::from_millis(client_age_ms)
> SERIAL_CONSOLE_IDLE_TIMEOUT
{
self.usart.clear_rx_data();
self.attached_serial_console_mgs = None;
}
}

return &self.attached_serial_console_mgs;
}

pub(crate) fn packet_to_mgs(
&mut self,
tx_buf: &mut [u8; gateway_messages::MAX_SERIALIZED_SIZE],
Expand All @@ -279,21 +298,8 @@ impl MgsHandler {
}

// Do we have an attached MGS instance that hasn't gone stale?
let sender = match &self.attached_serial_console_mgs {
Some(attached) => {
// Check whether we think this client has disappeared
let client_age_ms = sys_get_timer()
.now
.saturating_sub(attached.last_keepalive_received);
if Duration::from_millis(client_age_ms)
> SERIAL_CONSOLE_IDLE_TIMEOUT
{
self.usart.clear_rx_data();
self.attached_serial_console_mgs = None;
return None;
}
attached.sender
}
let sender = match &self.get_attached_nonidle_client() {
Some(attached) => attached.sender,
None => {
// Discard any buffered data and reset any usart-related timers.
self.usart.clear_rx_data();
Expand Down Expand Up @@ -746,7 +752,7 @@ impl SpHandler for MgsHandler {
return Err(SpError::RequestUnsupportedForComponent);
}

if self.attached_serial_console_mgs.is_some() {
if self.get_attached_nonidle_client().is_some() {
return Err(SpError::SerialConsoleAlreadyAttached);
}

Expand Down