mirror of
https://github.com/optim-enterprises-bv/openlan-cgw.git
synced 2025-10-30 01:42:20 +00:00
Connection processor: add a force TLS-accept timeout
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 <oleksandr.mazur@plvision.eu>
This commit is contained in:
@@ -105,7 +105,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();
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user