-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
os.uptime returns the wrong value #36244
Comments
Node uses sysinfo call to obtain the node/deps/uv/src/unix/cygwin.c Lines 28 to 36 in df0e2e3
the system command openat(AT_FDCWD, "/proc/uptime", O_RDONLY) = 3 Not sure why these are different. Can you compile this below code and run to see what it produces? $ cat foo.cc #include <stdio.h>
#include <sys/sysinfo.h>
#include <errno.h>
int main() {
struct sysinfo info;
if (sysinfo(&info) < 0) {
fprintf(stderr, "error calling sysinfo: %d\n", errno);
return -1;
}
fprintf(stderr, "system has been up for %ld seconds\n", info.uptime);
return 0;
} compare it with the output of |
I don't have access to the affected server right now, but I will post the output as soon as I can. Just out of curiosity: why are you looking at https://github.com/nodejs/node/blob/v10.x/deps/uv/src/unix/linux-core.c#L563-L578 I am by no means versed in Linux C programming, but according to the documentation, this function does not necessarily return the uptime, but the time since "some unspecified point in the past". It does say, however, that on Linux "that point corresponds to the number of seconds that the system has been running since it was booted," but I suspect that on this virtualization platform it returns something else. Maybe the time since the host was booted. |
sorry, you are right! I looked at a wrong location. so when you have access to the system, hope you will check a similar source, as opposed to what I posted. (Please let me know if you need a working code snippet out of it) |
I too tested in a virtual box, but got all the results matching, so not sure if it is specific to virtualization methods / os versions #include <time.h>
#include <errno.h>
#include <stdio.h>
int main() {
struct timespec now;
int r;
r = clock_gettime(CLOCK_BOOTTIME, &now);
if (r != 0) {
fprintf(stderr, "clock_gettime failed with %d\n", errno);
return errno;
}
fprintf(stderr, "system uptime: %ld\n", now.tv_sec);
return 0;
}
|
This confirms If I run the
I wonder why the Linux version of NodeJS doesn't also use |
@davedodo - I assume that you can confirm (outside of the software) that the actual boot time in this case is 36 days ? /cc @nodejs/libuv |
Yes, I can confirm that 36 days is the correct uptime. |
I am not strongly familiar with the |
Probably the fastest way to confirm this is the case (besides going through obscure and arcane OpenVZ documentation) is by contacting physical server admin and asking him the time of the last reboot (if he's willing to tell) |
I think it's probably a good idea to add a note to the documentation about this? |
@benjamingr - the issue with documenting is - documenting something like:
is going to largely limit the usability of the API - unless the programmer / user is able to externally verify such things and make calculated decisions in their program. A more practical approach would be to:
does it look reasonable to you? |
@schamberg97 - in my case, both Node.js and uptime return the same result. I can confirm my uptime of the virtual + physical machine as correctly returned. @davedodo also physically verified and confirmed their physical uptime, and as different between physical and virtual instances. Your points look promising, but where do we go from here, given the results? I too cannot find any documented behavior changes for |
Just wanted to reiterate: I did verify that the node/deps/uv/src/unix/cygwin.c Lines 28 to 36 in 89d664d
|
Yes, though to be clear I didn't mean "let's not fix it" I only meant "let's document it in the meantime until it is fixed" |
@gireeshpunathil Even under OpenVZ and Virtuozzo? I have just checked, the issue is real under OpenVZ. The guest instances use the same kernel as host, but their |
@gireeshpunathil Sorry, I misunderstood your comment initially :D. The |
@schamberg97 - thanks for the clarification.
this is what I get in my system. So the crux of what you are saying is that we can use this mechanism to reliably check the presence of mismatch between the two calls, right? |
@gireeshpunathil Exactly! :) |
Inside openVZ container it will produce the info about container's ID, IP and number of running processes:
|
@gireeshpunathil @benjamingr @davedodo Since there is no open issue on libuv repo referring this node.js issue, shall I open one? |
This should hopefully be resolved if/when libuv/libuv#3072 is merged |
Hi @schamberg97, I saw that libuv/libuv#3072 got landed -but is not in Node yet- (thanks for the help!), I' ll close this issue, but, feel free to reopen if needed :) |
The
os.uptime
function returns wrong values on some machines. I am using NodeJS 10 on Ubuntu 16.04 via the nodesource repository. The system'suptime
command returns07:36:53 up 36 days, 11:51
. Butrequire("os").uptime() / 3600 / 24
yields about 77 days. The system is a virtual server. The virtualization software used by the provider is Virtuozzo (I think).I tried the same on a bare metal machine at home with Ubuntu 18.04, but the returned time is correct there. I get the feeling that the virtualization has something to do with it. Anyway, I believe this should be fixed.
The text was updated successfully, but these errors were encountered: