-
Notifications
You must be signed in to change notification settings - Fork 624
EW-6888 Improve finishScheduled() outcome reporting #6606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -564,8 +564,35 @@ kj::Promise<void> IoContext::IncomingRequest::drain() { | |||||
| .exclusiveJoin(context->onAbort().catch_([](kj::Exception&&) {})); | ||||||
| } | ||||||
|
|
||||||
| kj::Promise<IoContext_IncomingRequest::FinishScheduledResult> IoContext::IncomingRequest:: | ||||||
| finishScheduled() { | ||||||
| // TODO | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MEDIUM] Bare |
||||||
| constexpr kj::Exception::DetailTypeId SCRIPT_KILLED_DETAIL_ID = 0x0ull; | ||||||
| constexpr kj::Exception::DetailTypeId INACTIVE_WEBSOCKETS_DETAIL_ID = 0x0ull; | ||||||
| constexpr kj::Exception::DetailTypeId SCRIPT_NOT_FOUND_DETAIL_ID = 0x0ull; | ||||||
|
Comment on lines
+568
to
+570
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] These three The existing IDs in the codebase all use unique random 64-bit values (e.g. I understand the |
||||||
|
|
||||||
| // TODO: Try to generalize this. Are all outcomes needed here? | ||||||
| EventOutcome outcomeFromException(kj::Exception& e) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [LOW] This function doesn't modify the exception — consider taking
Suggested change
|
||||||
| if (e.getType() == kj::Exception::Type::OVERLOADED) { | ||||||
| if (e.getDetail(SCRIPT_KILLED_DETAIL_ID) != kj::none) { | ||||||
| return EventOutcome::KILL_SWITCH; | ||||||
| } else if (e.getDetail(MEMORY_LIMIT_DETAIL_ID) != kj::none) { | ||||||
| return EventOutcome::EXCEEDED_MEMORY; | ||||||
| } else if (e.getDetail(CPU_LIMIT_DETAIL_ID) != kj::none) { | ||||||
| return EventOutcome::EXCEEDED_CPU; | ||||||
| } else if (e.getDetail(INACTIVE_WEBSOCKETS_DETAIL_ID) != kj::none) { | ||||||
| return EventOutcome::LOAD_SHED; | ||||||
| } else { | ||||||
| // TODO(later): We have many overloaded exceptions that can't be described as killSwitch, | ||||||
| // exceededCpu or exceededMemory. Should there be a new outcome type for them? | ||||||
| return EventOutcome::EXCEPTION; | ||||||
| } | ||||||
| } else if (e.getDetail(SCRIPT_NOT_FOUND_DETAIL_ID) != kj::none) { | ||||||
| return EventOutcome::SCRIPT_NOT_FOUND; | ||||||
| } else { | ||||||
| return EventOutcome::EXCEPTION; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| kj::Promise<EventOutcome> IoContext::IncomingRequest::finishScheduled() { | ||||||
| // TODO(someday): In principle we should be able to support delivering the "scheduled" event type | ||||||
| // to an actor, and this may be important if we open up the whole of WorkerInterface to be | ||||||
| // callable from any stub. However, the logic around async tasks would have to be different. We | ||||||
|
|
@@ -580,13 +607,22 @@ kj::Promise<IoContext_IncomingRequest::FinishScheduledResult> IoContext::Incomin | |||||
| context->incomingRequests.front().waitedForWaitUntil = true; | ||||||
|
|
||||||
| auto timeoutPromise = context->limitEnforcer->limitScheduled().then( | ||||||
| [] { return IoContext_IncomingRequest::FinishScheduledResult::TIMEOUT; }); | ||||||
| // TODO: I think there is a material difference between the scheduled limit being hit and | ||||||
| // actually hitting the CPU limit, we emit a NOSENTRY log for this case for queue events. How | ||||||
| // do we handle this best? | ||||||
| [] { return EventOutcome::EXCEEDED_CPU; }); | ||||||
| return context->waitUntilTasks.onEmpty() | ||||||
| .then([]() { return IoContext_IncomingRequest::FinishScheduledResult::COMPLETED; }) | ||||||
| .then([]() { return EventOutcome::OK; }) | ||||||
| .exclusiveJoin(kj::mv(timeoutPromise)) | ||||||
| .exclusiveJoin(context->onAbort().then([] { | ||||||
| return IoContext_IncomingRequest::FinishScheduledResult::ABORTED; | ||||||
| }, [](kj::Exception&&) { return IoContext_IncomingRequest::FinishScheduledResult::ABORTED; })); | ||||||
| // abortFulfiller should only ever be rejected instead of being fulfilled, but return an | ||||||
| // exception outcome if it does happen | ||||||
| return EventOutcome::EXCEPTION; | ||||||
| }, [](kj::Exception&& e) { | ||||||
| // TODO: If we end up returning exception here, that's still a case that's hard to make sense of | ||||||
| return outcomeFromException(e); | ||||||
| // TODO: Just call reportFailure() here? | ||||||
| })); | ||||||
| } | ||||||
|
|
||||||
| class IoContext::PendingEvent: public kj::Refcounted { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MEDIUM] Leftover debug artifacts — the bare
// TODOon line 965 and the commented-out old code on line 967 look like they shouldn't be merged. If there's an open question here, make the TODO actionable; otherwise please clean these up.