| 279 | // so this is where the JS thread proves it is responsive again. getFunctionName() is |
| 280 | // safe here: this is the JS thread, the only writer of its lazy cache. |
| 281 | auto stillOverdue = taskScheduler->onOverdueDeadlineCallCompleted(); |
| 282 | if (stillOverdue == 0) { |
| 283 | [[maybe_unused]] auto failedFast = taskScheduler->takeFastFailedDeadlineCalls(); |
| 284 | [[maybe_unused]] auto lateByMs = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 285 | std::chrono::steady_clock::now() - call->dispatchedAt) |
| 286 | .count(); |
| 287 | VALDI_WARN(self->getContext()->getLogger(), |
| 288 | "JS thread caught up on overdue sync call to '{}' {}ms after dispatch; {} bounded calls " |
| 289 | "were failed fast meanwhile", |
| 290 | self->getFunctionName(), |
| 291 | lateByMs, |
| 292 | failedFast); |
| 293 | } |
| 294 | }); |
| 295 | |
| 296 | if (std::future_status::ready == future.wait_until(deadline)) { |
| 297 | return future.get(); |
| 298 | } |
| 299 | |
| 300 | // Count before claiming the timeout so the JS task, which decrements only after it observes |
| 301 | // TimedOut, can never see the counter at zero. |
| 302 | taskScheduler->onDeadlineCallTimedOut(); |
| 303 | auto expected = DeadlineCall::State::Pending; |
| 304 | if (!call->state.compare_exchange_strong(expected, DeadlineCall::State::TimedOut)) { |
| 305 | taskScheduler->onOverdueDeadlineCallCompleted(); |
| 306 | return future.get(); |
| 307 | } |
| 308 | |
| 309 | // Name what the JS thread is doing instead of running us. The attribution only has content |
| 310 | // when ANR diagnostics are on, and it is the one signal that tells a slow JS thread apart from |
| 311 | // a JS thread that is itself blocked on the main thread. |
| 312 | // Built from the immutable ReferenceInfo rather than getFunctionName(): that cache is lazily |
| 313 | // written on the JS thread (doJsCall), which may be initializing it right now. |
| 314 | [[maybe_unused]] auto waitedMs = |
| 315 | std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - call->dispatchedAt) |
| 316 | .count(); |
nothing calls this directly
no test coverage detected