Skip to content
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 float instead of integer #41636

Closed
davedodo opened this issue Jan 21, 2022 · 7 comments
Closed

os.uptime returns float instead of integer #41636

davedodo opened this issue Jan 21, 2022 · 7 comments
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.

Comments

@davedodo
Copy link

davedodo commented Jan 21, 2022

Version

v14.18.3

Platform

Linux 5.4.0 #1 SMP Thu Apr 22 16:18:59 MSK 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

os

What steps will reproduce the bug?

I just upgraded from Node.js 12 to 14 (on Ubuntu via nodesource repository) and found that require("os").uptime() now returns a float and no longer an integer as the documentation states. Tested on Ubuntu 18.04 on VirtualBox and Ubuntu 20.04 on a Virtuozzo container. So this is either a bug or the documentation needs an update.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

os.uptime should return an integer.

What do you see instead?

os.uptime returns a number that is not an integer.

Additional information

No response

@richardlau
Copy link
Member

Some history #12291.

@VoltrexKeyva VoltrexKeyva added the os Issues and PRs related to the os subsystem. label Jan 21, 2022
@lal12
Copy link
Contributor

lal12 commented Jan 28, 2022

Yes I've noticed this too. There was a change in libuv (libuv/libuv@77a2394) which now reads /proc/uptime instead of using clock_gettime(CLOCK_MONOTONIC and /proc/uptime contains a fractional output. So either this behavior should be changed or the docs should be adjusted to say that it is a fractional number on some systems. I would prefer fractional seconds, since a math.floor is easily doable and a higher precision might be useful sometimes.

@lal12
Copy link
Contributor

lal12 commented Jan 28, 2022

I created an additional issue for this in libuv libuv/libuv#3447

@davedodo
Copy link
Author

@lal12 You are correct. Funny, this change is related to bug report #36244 I filed in 2020 because clock_gettime doesn't work properly inside OpenVZ/Virtuozzo containers. Fractional seconds are cool, but it would be a breaking change. 🤔

@lal12
Copy link
Contributor

lal12 commented Jan 31, 2022

It depends a bit on how you define a breaking change, there is no datatype change so nothing what totally breaks. But yeah it can lead to strange behavior if someone relies on an integer. I found this issue since some number formatting code of ours relied on integers.

However for quite a while windows has returned fractionals in this API, which also was changed.

@lal12
Copy link
Contributor

lal12 commented Feb 2, 2022

libuv already returned fractional uptime for some architecture, just did a PR there to return fractions on win. So changing this to round down would be a "breaking" change too, especially since some versions are already released with this behavior. I really think updating the docs accordingly is best.

I can do a PR if wished for.

@Mesteery Mesteery added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Feb 2, 2022
@santigimeno
Copy link
Member

This should be fixed as #42340 has landed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants