Skip to content

Commit

Permalink
Connection processor: add a force TLS-accept timeout
Browse files Browse the repository at this point in the history
Whenever TLS accept (tungstenite::accept(tls_stream))
blocks for too long (>15 seconds), stop trying
to accept the stream using tokio_selector.
This is done to ensure we don't have a hang
connection processor that might hang for a very
long period of time waiting for a connection to be
accepted.

Also run cargo fmt to fix some import indentation.

Signed-off-by: Oleksandr Mazur <[email protected]>
  • Loading branch information
Cahb committed Dec 11, 2024
1 parent cd35ca6 commit b2867ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/cgw_connection_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,24 @@ impl CGWConnectionProcessor {
client_cn: MacAddress,
allow_mismatch: bool,
) -> Result<()> {
let ws_stream = tokio_tungstenite::accept_async(tls_stream).await?;
let ws_stream = tokio::select! {
_val = tokio_tungstenite::accept_async(tls_stream) => {
match _val {
Ok(s) => s,
Err(e) => {
error!("Failed to accept TLS stream from: {}! Reason: {}. Closing connection",
self.addr, e);
return Err(Error::ConnectionProcessor("Failed to accept TLS stream!"));
}
}
}
// TODO: configurable duration (upon server creation)
_val = sleep(Duration::from_millis(15000)) => {
error!("Failed to accept TLS stream from: {}! Closing connection", self.addr);
return Err(Error::ConnectionProcessor("Failed to accept TLS stream for too long"));
}

};

let (sink, mut stream) = ws_stream.split();

Expand Down
8 changes: 4 additions & 4 deletions src/cgw_ucentral_switch_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::{collections::HashMap, str::FromStr};
use crate::cgw_errors::{Error, Result};

use crate::cgw_ucentral_parser::{
CGWUCentralEvent, CGWUCentralEventLog, CGWUCentralEventState, CGWUCentralEventStateClients,
CGWUCentralEventStateClientsData, CGWUCentralEventStateClientsType,
CGWUCentralEventStateLLDPData, CGWUCentralEventStateLinks, CGWUCentralEventStatePort,
CGWUCentralEventType, CGWUCentralJRPCMessage, CGWUCentralEventReply
CGWUCentralEvent, CGWUCentralEventLog, CGWUCentralEventReply, CGWUCentralEventState,
CGWUCentralEventStateClients, CGWUCentralEventStateClientsData,
CGWUCentralEventStateClientsType, CGWUCentralEventStateLLDPData, CGWUCentralEventStateLinks,
CGWUCentralEventStatePort, CGWUCentralEventType, CGWUCentralJRPCMessage,
};

fn parse_lldp_data(
Expand Down

0 comments on commit b2867ac

Please sign in to comment.