New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uv_uptime returns incorrect values on OpenVZ containers. #3068
Comments
Option 1 is probably off the table. In 3a1be72 and 1c22b44 I switched some things from I think (not 100% sure) lxc intercepts What could probably work - and is virtualization agnostic - is to read the first field from Parsing a file is much more expensive than a vDSO "system call" (it's usually serviced from the vDSO without making an actual system call) but I don't think that matters for |
That’s how I saw the solution as well initially, but I had some aversion to it, as it is more expensive. I could make a PR today, if I am not disturbed by other matters. Otherwise, I would have no problem if someone else does it. |
I'd say go for it. :-) |
This change fixes libuv#3068 on OpenVZ Containers in Linux
First check `/proc/uptime`, then fallback to `clock_gettime()`. Fixes: libuv#3068 Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
First check `/proc/uptime`, then fallback to `clock_gettime()`. Fixes: libuv#3068 PR-URL: libuv#3072 Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Linux vps1607355603 4.15.0 #1 SMP Tue Aug 25 11:59:26 MSK 2020 x86_64 x86_64 x86_64 GNU/Linux
libuv/src/unix/linux-core.c
Lines 606 to 628 in 9c6cec8
Hey there :) It appears that libuv in OpenVZ environments returns incorrect values. For instance, if one were to check the uptime using
cat /proc/uptime
and Node.js'sos.uptime()
, one would get the following results respectively:3187731.82
and6740816
. In other words, libuv returns results that are higher than container's uptime. Same erroneous result is achieved with this code provided by @gireeshpunathil:To get into the root of the problem, we need to understand how OpenVZ operates. OpenVZ consists of a host Linux system with highly patched kernel, which then runs the containers. Unfortunately, all containers share the host kernel, but are provided with a separate simulation of
/proc/
(procfs) filesystem for each container. Thus, the earlier mentioned6740816
uptime from libuv coincides with the uptime of the physical host system.In practice, this means that the
clock_gettime
is inherently unreliable on OpenVZ systems. It is suggested by @davedodo on a related node.js issue nodejs/node#36244 (comment) thatsysinfo
function works correctly with OpenVZ systems (like in Cygwin implementation). However, there might be other alternatives that I (we?) are unaware of.It is my understanding that this issue concerns only OpenVZ/Virtuozo. Thus, in order to check, whether the system is an OpenVZ container, it appears sufficient to check that
/proc/vz/veinfo
file exists at launch time (it contains container ID, public IP of current container and current number of running processes).I am not providing any PR at this point, because this issue may involve quite a bit of decision making on this issue, with a non-exhausting list of three alternatives:
uv_uptime
entirely usingsysinfo
for all casesclock_gettime
inuv_uptime
on OpenVZ and usesysinfo
insteadThe text was updated successfully, but these errors were encountered: