ockam icon indicating copy to clipboard operation
ockam copied to clipboard

Disable Ockam Heartbeats for Tcp on server side

Open SanjoDeundiak opened this issue 2 years ago • 5 comments

While we don't support TCP-level keep-alive #3450, we occassionally send empty Ockam packets in tcp workers to:

  1. Keep connection alive
  2. Find out early if connection was closed We call that Heartbeat. Thos packets are sent here and they're just ignored while receiving here.

The idea is that only client side (the side that initiates connection) should do that, while currently rust doesn't check that and always sends them. Possible solution is to store information about connection role (client or server) in TcpSendWorker and enable/disable heartbeats based on that

SanjoDeundiak avatar Sep 16 '22 13:09 SanjoDeundiak

Hi @SanjoDeundiak, can i work on this issue?

michealkeines avatar Sep 17 '22 06:09 michealkeines

@michealkeines of course, all yours.

mrinalwadhwa avatar Sep 17 '22 15:09 mrinalwadhwa

I checked the TcpSendWorker struct

I have tried your solution, we can add is_initiator and call schedule_heartbeat() based on this value

pub(crate) struct TcpSendWorker {
    ...
    is_initiator: bool,
}

if self.is_initiator {
    self.schedule_heartbeat().await?;
}

TCP send worker pair could be created using TcpSendWorker::new_pair, we can update these two calls

//listener.rs:60 - we dont want listeners to start heartbeats as they act as server
TcpSendWorker::new_pair(ctx, handle_clone, Some(stream), peer, Vec::new(), false).await?;

//sender.rs:138 - we want any send call to start heartbeats
Self::new_pair(ctx, router_handle, stream, peer, hostnames, true).await?;

Please correct me, if i have missed something. @mrinalwadhwa @SanjoDeundiak

michealkeines avatar Sep 17 '22 17:09 michealkeines

@michealkeines sounds great!

SanjoDeundiak avatar Sep 19 '22 08:09 SanjoDeundiak

@michealkeines hold on, we may have race condition with #3492

SanjoDeundiak avatar Sep 19 '22 08:09 SanjoDeundiak

@michealkeines I think this issue is superseded by #3492

SanjoDeundiak avatar Sep 27 '22 15:09 SanjoDeundiak

@michealkeines Thank you for spending time on this!

mrinalwadhwa avatar Sep 27 '22 15:09 mrinalwadhwa