From c11f245d643ee5b5ee2d530009123b589f7ca7b5 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 26 Jun 2016 12:04:47 +0100 Subject: [PATCH] Cope with writing a frame failing If a client disconnects suddenly then we may get an error trying to map its grant to send the frame. Fixes #8. --- firewall.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/firewall.ml b/firewall.ml index 97ce185..4b98302 100644 --- a/firewall.ml +++ b/firewall.ml @@ -16,7 +16,14 @@ let transmit ~frame iface = cases. *) let frame = fixup_checksums frame |> Cstruct.concat in let packet = Cstruct.shift frame Wire_structs.sizeof_ethernet in - iface#writev [packet] + Lwt.catch + (fun () -> iface#writev [packet]) + (fun ex -> + Log.warn (fun f -> f "Failed to write packet to %a: %s" + Ipaddr.V4.pp_hum iface#other_ip + (Printexc.to_string ex)); + Lwt.return () + ) let forward_ipv4 t frame = let packet = Cstruct.shift frame Wire_structs.sizeof_ethernet in