Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v2.8.0 (2020-09-28)

* Netif.listen: do not catch out of memory exception (#49 @hannesm)

### v2.7.0 (30-Oct-2019)

* Adapt to mirage-net 3.0.0 changes (@hannesm)
Expand Down
12 changes: 1 addition & 11 deletions src/netif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ let rec read t buf =
| Error `Disconnected -> Lwt.return (Error `Disconnected)
| Ok buf -> Lwt.return (Ok buf)

let safe_apply f x =
Lwt.catch
(fun () -> f x)
(function
| Out_of_memory -> Lwt.fail Out_of_memory
| exn ->
Log.err (fun m -> m "[listen] error while handling %s, continuing. bt: %s"
(Printexc.to_string exn) (Printexc.get_backtrace ()));
Lwt.return_unit)

(* Loop and listen for packets permanently *)
(* this function has to be tail recursive, since it is called at the
top level, otherwise memory of received packets and all reachable
Expand All @@ -123,7 +113,7 @@ let rec listen t ~header_size fn =
let buf = Cstruct.create (t.mtu + header_size) in
let process () =
read t buf >|= function
| Ok buf -> Lwt.async (fun () -> safe_apply fn buf) ; Ok ()
| Ok buf -> Lwt.async (fun () -> fn buf) ; Ok ()
| Error `Canceled -> Error `Disconnected
| Error `Disconnected -> t.active <- false ; Error `Disconnected
in
Expand Down