Skip to content

Commit

Permalink
Emit a warning if TCP keepalives are used
Browse files Browse the repository at this point in the history
As reported in mirage#367, the implementation of keepalives can use unexpected
amounts of memory under some circumstances. Until the fix is ready, emit
a single warning if a client enables keep-alives.

Signed-off-by: David Scott <dave@recoil.org>
  • Loading branch information
djs55 committed Jun 15, 2018
1 parent f58e93b commit a6999cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/tcp/flow.ml
Expand Up @@ -315,6 +315,8 @@ struct
User_buffer.Rx.add_r urx None >>= fun () ->
Lwt.return_unit

let emitted_keepalive_warning = ref false

let new_pcb t params id keepalive =
let mtu_mss = Ip.mtu t.ip - Tcp_wire.sizeof_tcp in
let { tx_wnd; sequence; options; tx_isn; rx_wnd; rx_wnd_scaleoffer } =
Expand Down Expand Up @@ -363,7 +365,13 @@ struct
(* Set up the keepalive state if requested *)
let keepalive = match keepalive with
| None -> None
| Some config -> Some (KEEPALIVE.create config (keepalive_cb t id wnd state urx) t.clock) in
| Some config ->
(* Only omit the warning once to avoid spamming the logs *)
if not !emitted_keepalive_warning then begin
Log.warn (fun f -> f "using keep-alives can cause excessive memory consumption: https://github.com/mirage/mirage-tcpip/issues/367");
emitted_keepalive_warning := true
end;
Some (KEEPALIVE.create config (keepalive_cb t id wnd state urx) t.clock) in
(* Construct basic PCB in Syn_received state *)
let pcb = { state; rxq; txq; wnd; id; ack; urx; utx; keepalive } in
(* Compose the overall thread from the various tx/rx threads
Expand Down

0 comments on commit a6999cc

Please sign in to comment.