Skip to content

uptime RPC returns 0 on first invocation #34423

Closed

Description

@carloantinarella

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

First time bitcoin-cli uptime is called, output is always zero.

Expected behaviour

Expected behavior should be first time invocation of bitcoin-cli uptime shows the actual bitcoind uptime.

Steps to reproduce

On Linux:

  1. ./build/bin/bitcoind -regtest -daemon
  2. sleep 10
  3. ./build/bin/bitcoin-cli -regtest uptime

Output is zero, while non-zero is expected.

Relevant log output

No response

How did you obtain Bitcoin Core

Compiled from source

What version of Bitcoin Core are you using?

v30.99.0-c0e6556e4f51

Operating system and version

Ubuntu 22.04.5 LTS

Machine specifications

No response

Activity

  1. carloantinarella commented on Jan 27, 2026

    @carloantinarella
    ContributorAuthor

    Probably caused by changes introduced in #34328

    I guess the function GetUptime() shall be called at least once in the startup phase to initialize the static variable g_startup_time.
    Also rpc_uptime.py could be updated with dedicated check.

    If ok, I would be happy to contribute with a PR for this.

  2. maflcko commented on Jan 27, 2026

    @maflcko
    Member

    I guess the function GetUptime() shall be called at least once in the startup phase to initialize the static variable g_startup_time.

    Right, good catch. I think this was introduced by me in #34328 (comment)

  3. added this to the 31.0 milestone on Jan 27, 2026
  4. carloantinarella commented on Jan 28, 2026

    @carloantinarella
    ContributorAuthor

    Thank you for the feedback.
    I did a test calling the function in AppInitMain, right before Step 4a code, and it works fine.
    Would it be a good solution?
    Is there already a plan for fixing this issue?

  5. l0rinc commented on Jan 28, 2026

    @l0rinc
    Contributor

    Thanks @carloantinarella, looks like we all misunderstood your original report.
    I pushed a fix to #34437, added you as coauthor.
    Thanks for testing it, keep it up!

  6. dergoegge commented on Jan 29, 2026

    @dergoegge
    Member

    @carloantinarella out of curiosity what is your usecase for the uptime RPC? Any reason you prefer it over querying your OS for the uptime of the bitcoind process?

  7. carloantinarella commented on Jan 29, 2026

    @carloantinarella
    ContributorAuthor

    No special needs, I just use it to check if the node is up and running. It's os agnostic and returns plain number (good for quick scripting).

  8. added a commit that references this issue on Feb 6, 2026
    9ec1ae0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions