ocsigen / lwt

OCaml promises and concurrent I/O
https://ocsigen.org/lwt
MIT License
718 stars 177 forks source link

Lwt_unix.sleep vs system time update #473

Open ErwanGa opened 7 years ago

ErwanGa commented 7 years ago

Lwt_unix.sleep seems not using CLOCK_MONOTONIC_RAW clock. This means that Lwt_unix.sleep can be affected by discontinuous jumps in the system time or NTP adjustment. Ie Lwt_unix.sleep 2.0 duration could be 3 hours if system time go 3 hours in the past. This creates a kind of DoS

aantron commented 7 years ago

Is this issue referring to the select engine, which, I see, is using gettimeofday, or libev?

ErwanGa commented 7 years ago

Hi This is linked to call here https://github.com/ocsigen/lwt/blob/fa4fa370aacdfe0f6f86bb3716c0bac0cbe3f28d/src/unix/lwt_unix.cppo.ml#L130-L134 I suspect that the usage of gettimeofday is the root cause of my issue Erwan

aantron commented 7 years ago

That call eventually triggers one of the two sets of code from my message, so I'd like to get an idea of which one it is for you :) I haven't looked into how the libev function is implemented in a while, but it's possible they are both using a non-monotonic clock anyway, actually.

What operating system are you on? Have you done anything to explicitly choose libev while using Lwt? Is libev (the C library) installed on your system? Is conf-libev (the OPAM package) installed in your switch?

ErwanGa commented 7 years ago

I'm under Linux - buildroot cross-compiled/i386 version libev-dev libev4, conf-libev were not not installed

I've compiled/installed them, the problem does not appear

aantron commented 7 years ago

Ok, thanks. We should still keep this open a a reminder to fix it in the select code, if that can be done portably, until either it's fixed or that code is obsolete.

ErwanGa commented 7 years ago

Thanks for all I'll probably use libev for the moment. Hoping that no spurious bug will appear due to this change erwan