Skip to content

Commit

Permalink
Attempt to log the stack where cross-request promises are being resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 25, 2024
1 parent b3bd93a commit 4f89424
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,35 @@ Worker::Isolate::Isolate(kj::Own<Api> apiParam,
v8::Local<v8::Value> argument)> callback) -> v8::Maybe<void> {
try {
auto& js = jsg::Lock::from(isolate);

{
// TODO(soon): Hopefully this logging is temporary. We want to get an idea
// of where the cross request promises are being resolved just in general.
// To do so we need to try to capture a stack. We do so by creating an error
// object and logging it.
v8::HandleScope handleScope(isolate);
auto err =
v8::Exception::Error(js.str("Cross Request Promise Resolve"_kj)).As<v8::Object>();
jsg::check(err->Set(js.v8Context(), js.str("name"_kj), js.str("Warning"_kj)));
auto stack = jsg::check(err->Get(js.v8Context(), js.str("stack"_kj)));
// Let's only log if there's actually a useful stack in the log.
auto msg = kj::str("NOSENTRY ", stack);
// This check is meant to prevent spamming the logs with messages that do
// not actually provide any useful information.
if (msg != "NOSENTRY Warning: Cross Request Promise Resolve") {
KJ_LOG(WARNING, kj::str("NOSENTRY ", stack));
} else {
// If we get here, it means we don't have a useful JS stack trace.
// Either the stack trace limit was set to zero for some reason or
// this resolve/reject originated from inside the runtime where a
// JS stack trace is not available. Let's emit the warning with a
// C++ stack instead.
// TODO(review): Is this worthwhile? Does it give us enough useful signal?
LOG_PERIODICALLY(WARNING, "NOSENTRY Warning: Cross Request Promise Resolve\n",
kj::getStackTrace());
}
}

// The promise tag is generally opaque except for right here. The tag
// wraps an instanceof kj::Own<IoCrossContextExecutor>, which wraps an atomically
// refcounted pointer to the DeleteQueue for the correct isolate.
Expand Down

0 comments on commit 4f89424

Please sign in to comment.