Skip to content

Fix JsRpcPromise::Resolved context checking. - #2143

Merged
kentonv merged 1 commit into
mainfrom
kenton/fix-jsrpc-context-check
May 22, 2024
Merged

Fix JsRpcPromise::Resolved context checking.#2143
kentonv merged 1 commit into
mainfrom
kenton/fix-jsrpc-context-check

Conversation

@kentonv

@kentonv kentonv commented May 20, 2024

Copy link
Copy Markdown
Member

IoContext::WeakRef is a KJ I/O object, so kj::Own<IoContext::WeakRef> is not safe to hold from a JSG object. Instead, it would need to be kj::IoOwn<IoContext::WeakRef>. But, at that point we don't even need the WeakRef anymore because dereferencing the IoOwn itself will do exactly the check that we were using the WeakRef to do.

Actually, all we really need here is an IoPtr<T> (the type of T is irrelevant) which we can attempt to dereference in order to effect the context check we want.

@kentonv
kentonv requested a review from jasnell May 20, 2024 22:34
@kentonv
kentonv requested review from a team as code owners May 20, 2024 22:34
@kentonv
kentonv requested a review from ObsidianMinor May 20, 2024 22:34
`IoContext::WeakRef` is a KJ I/O object, so `kj::Own<IoContext::WeakRef>` is not safe to hold from a JSG object. Instead, it would need to be `kj::IoOwn<IoContext::WeakRef>`. But, at that point we don't even need the `WeakRef` anymore because dereferencing the `IoOwn` itself will do exactly the check that we were using the `WeakRef` to do.

Actually, all we really need here is an `IoPtr<T>` (the type of `T` is irrelevant) which we can attempt to dereference in order to effect the context check we want.
@kentonv
kentonv force-pushed the kenton/fix-jsrpc-context-check branch from 6c324b2 to 6a4d54c Compare May 20, 2024 22:35

@jasnell jasnell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice.. I kind of expected it would be something along these lines.

// Dummy IoPtr to self, used only to verify that we're running in the correct context.
// (Dereferencing from the wrong context would throw an exception.)
// Note: Can't use IoContext::WeakRef here because it's not thread-safe (it's only intended to
// be helf from KJ I/O objects, but this is a JSG object).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// be helf from KJ I/O objects, but this is a JSG object).
// be held from KJ I/O objects, but this is a JSG object).

@kentonv
kentonv merged commit 1917675 into main May 22, 2024
@kentonv
kentonv deleted the kenton/fix-jsrpc-context-check branch May 22, 2024 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants