lwt icon indicating copy to clipboard operation
lwt copied to clipboard

Lwt_unix.sleep vs system time update

Open ErwanGa opened this issue 7 years ago • 6 comments

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

ErwanGa avatar Sep 26 '17 06:09 ErwanGa

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

aantron avatar Sep 26 '17 09:09 aantron

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

ErwanGa avatar Sep 26 '17 10:09 ErwanGa

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?

aantron avatar Sep 26 '17 10:09 aantron

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

ErwanGa avatar Sep 26 '17 11:09 ErwanGa

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.

aantron avatar Sep 26 '17 12:09 aantron

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

ErwanGa avatar Sep 26 '17 12:09 ErwanGa