Skip to content
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

Improve new IoOwn logging #2035

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/workerd/io/io-context.c++
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ void IoContext::requireCurrent() {
KJ_REQUIRE(threadLocalRequest == this, "request is not current in this thread");
}

void IoContext::checkFarGet(const DeleteQueue* expectedQueue, kj::StringPtr type) {
void IoContext::checkFarGet(const DeleteQueue* expectedQueue, const std::type_info& type) {
KJ_ASSERT(expectedQueue);
requireCurrent();

Expand Down Expand Up @@ -1273,9 +1273,9 @@ void IoContext::requireCurrentOrThrowJs(WeakRef& weak) {
throwNotCurrentJsError();
}

void IoContext::throwNotCurrentJsError(kj::Maybe<kj::StringPtr> maybeType) {
auto type = maybeType.map([](kj::StringPtr type) {
return kj::str(" (I/O type: ", type, ")");
void IoContext::throwNotCurrentJsError(kj::Maybe<const std::type_info&> maybeType) {
auto type = maybeType.map([](const std::type_info& type) {
return kj::str(" (I/O type: ", jsg::typeName(type), ")");
}).orDefault(kj::String());

if (threadLocalRequest != nullptr && threadLocalRequest->actor != kj::none) {
Expand Down
5 changes: 3 additions & 2 deletions src/workerd/io/io-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
static void requireCurrentOrThrowJs(WeakRef& weak);

// Just throw the error that requireCurrentOrThrowJs() would throw on failure.
[[noreturn]] static void throwNotCurrentJsError(kj::Maybe<kj::StringPtr> maybeType = kj::none);
[[noreturn]] static void throwNotCurrentJsError(
kj::Maybe<const std::type_info&> maybeType = kj::none);

// -----------------------------------------------------------------
// Task scheduling and object storage
Expand Down Expand Up @@ -811,7 +812,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler

void taskFailed(kj::Exception&& exception) override;
void requireCurrent();
void checkFarGet(const DeleteQueue* expectedQueue, kj::StringPtr type);
void checkFarGet(const DeleteQueue* expectedQueue, const std::type_info& type);

kj::Maybe<jsg::JsRef<jsg::JsObject>> promiseContextTag;

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/io-own.c++
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void DeleteQueue::scheduleDeletion(OwnedObject* object) const {
}
}

void DeleteQueue::checkFarGet(const DeleteQueue* deleteQueue, kj::StringPtr type) {
void DeleteQueue::checkFarGet(const DeleteQueue* deleteQueue, const std::type_info& type) {
IoContext::current().checkFarGet(deleteQueue, type);
}

Expand Down
11 changes: 4 additions & 7 deletions src/workerd/io/io-own.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class DeleteQueue: public kj::AtomicRefcounted {
// Implements the corresponding methods of IoContext and ActorContext.
template <typename T> IoOwn<T> addObject(kj::Own<T> obj, OwnedObjectList& ownedObjects);

static void checkFarGet(const DeleteQueue* deleteQueue, kj::StringPtr type);
static void checkFarGet(const DeleteQueue* deleteQueue, const std::type_info& type);
};

template <typename T>
Expand Down Expand Up @@ -288,15 +288,13 @@ IoPtr<T>& IoPtr<T>::operator=(decltype(nullptr)) {

template <typename T>
inline T* IoOwn<T>::operator->() {
auto type = jsg::typeName(typeid(T));
DeleteQueue::checkFarGet(deleteQueue, type);
DeleteQueue::checkFarGet(deleteQueue, typeid(T));
return item->ptr;
}

template <typename T>
inline IoOwn<T>::operator kj::Own<T>() && {
auto type = jsg::typeName(typeid(T));
DeleteQueue::checkFarGet(deleteQueue, type);
DeleteQueue::checkFarGet(deleteQueue, typeid(T));
auto result = kj::mv(item->ptr);
OwnedObjectList::unlink(*item);
item = nullptr;
Expand All @@ -306,8 +304,7 @@ inline IoOwn<T>::operator kj::Own<T>() && {

template <typename T>
inline T* IoPtr<T>::operator->() {
auto type = jsg::typeName(typeid(T));
DeleteQueue::checkFarGet(deleteQueue, type);
DeleteQueue::checkFarGet(deleteQueue, typeid(T));
return ptr;
}

Expand Down
Loading