Skip to content

Commit

Permalink
Log debug information when queue events time out due to lingering wai…
Browse files Browse the repository at this point in the history
…tUntil tasks
  • Loading branch information
jbwcloudflare committed Feb 22, 2024
1 parent fbb299f commit 304cb49
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/workerd/api/queue.c++
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,27 @@ kj::Promise<WorkerInterface::CustomEvent::Result> QueueCustomEventImpl::run(
// reuse the scheduled worker logic and timeout for now.
auto completed = co_await incomingRequest->finishScheduled();

// Log some debug info if the timeout was encountered
// Log some debug info if the request did not complete fully:
// In particular, detect whether or not the users queue() handler function completed
// and include info about other waitUntil tasks that may have caused the request to timeout.
if (!completed) {
// TODO(now) log success vs error cases
kj::String statusStr;
KJ_SWITCH_ONEOF(queueEventHolder->event->getCompletionStatus()) {
KJ_CASE_ONEOF(i, QueueEvent::Incomplete) {
statusStr = kj::str("Incomplete");
break;
}
KJ_CASE_ONEOF(s, QueueEvent::CompletedSuccessfully) {
statusStr = kj::str("Completed Succesfully");
break;
}
KJ_CASE_ONEOF(e, QueueEvent::CompletedWithError) {
statusStr = kj::str("Completed with error:", e.error);
break;
}
}
auto taskTrace = incomingRequest->getContext().getWaitUntilTasks().trace();
KJ_LOG(WARNING, kj::str("Queue event timed out due to lingering waitUntil tasks:\n", taskTrace));
KJ_LOG(WARNING, "NOSENTRY queue event timed out. Status: ", statusStr, ". Tasks: ", taskTrace);
}

co_return WorkerInterface::CustomEvent::Result {
Expand Down

0 comments on commit 304cb49

Please sign in to comment.