Commit 67273e9
[fix](be) Clamp MonotonicStopWatch elapsed time to non-negative
Problem Summary: MonotonicStopWatch::elapsed_time() can return a small
negative value (e.g. -203 ns) due to rare CLOCK_MONOTONIC rollbacks.
When stop() accumulates this into _total_time and _fresh_profile_counter()
sets it on a RuntimeProfile::Counter, the DCHECK asserting value > -1
fires and crashes the process.
Stack trace:
RuntimeProfile::Counter::set() at runtime_profile.h:222
PipelineTask::close() at pipeline_task.cpp:925
close_task() at task_scheduler.cpp:86
The fix clamps the running-case delta in elapsed_time() and
elapsed_time_seconds() to max(0, delta). Since stop() calls
elapsed_time() while _running is still true, _total_time can never
accumulate a negative value, preventing the crash for all downstream
callers.
None
- Test: No need to test (clock rollback is non-deterministic hardware behavior; the fix is a trivial arithmetic clamp)
- Behavior changed: No
- Does this need documentation: No
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent cb1876f commit 67273e9
1 file changed
+18
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | | - | |
81 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| |||
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
90 | | - | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
0 commit comments