Skip to content

system suspension is detected as a blocked event loop #13

@matthew-nicholson-anrok

Description

Environment

@sentry-internal/node-native-stacktrace@npm:0.2.1

On linux and macos.

Steps to Reproduce

  1. Enable eventLoopBlockIntegration.
  2. Run node instance with eventLoopBlockIntegration enabled on Google Cloud Run with the instance in request billing mode. This will also work from a laptop.
  3. Observe EventLoopBlocked notifications every time the system suspends.

Expected Result

System suspension should not be detected as a blocked event loop.

Actual Result

System suspension is detected and reported as a blocked event loop

Additional information

The event loop block integration currently uses std::chrono::system_clock::now() for detecting when the event loop is blocked (code). On linux, Gcc's libstdc++ uses clock_gettime() with CLOCK_REALTIME to or gettimeofday() get the time depending on the settings. The documentation specifically states that CLOCK_MONOTONIC can be used to ignore time when the system is suspended. The std::chrono::steady_clock::now() implementation on linux uses this call, but on macos llvm's libcxx specifically chooses CLOCK_MONOTONIC_RAW on that platform so that the clock tracks suspends (docs). On macos you want CLOCK_UPTIME_RAW or CLOCK_UPTIME_RAW_APPROX. On windows you want QueryUnbiasedInterruptTimePercise() or QueryUnbiasedInterruptTime().

So basically, you need to implement a custom time function that does the right thing on each platform as there doesn't appear to be one in the standard library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions