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

Add a new overload of Socket::handleProxyStatus for internal use #975

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

a-robinson
Copy link
Member

So that I can handle initial connection errors on connections that were established without using HTTP connect.

void Socket::handleProxyStatus(jsg::Lock& js, kj::Promise<kj::Maybe<kj::Exception>> connectResult) {
// It's kind of weird to take a promise that resolves to a Maybe<Exception> but we can't just use
// a Promise<void> and put our logic in the error handler because awaitIo's errorFunc isn't passed
// the jsg::Lock, which we need to have in the error case.
Copy link
Member

Choose a reason for hiding this comment

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

Note for later: should we update awaitIo so that it does pass the jsg::Lock?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should also update it to be awaitable

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this sounds like a bug in awaitIo that we should just fix instead of work around.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a little bit more than I had mentioned previously -- currently the only code path that passes a jsg::Lock is if your awaited promise resolves to a non-void result and if you're on the success callback. Even if I added a jsg::Lock to the error callback that wouldn't help in this particular case since I had been trying to use a Promise<void>, and as of today both the success and error callbacks aren't given a jsg::Lock in that case.

I'll leave it as a cleanup for now rather than boiling the ocean on all the awaitIo overloads.

auto result = context.awaitIo(js, kj::mv(connectResult),
[this, self = JSG_THIS](jsg::Lock& js, kj::Maybe<kj::Exception> result) -> void {
KJ_IF_MAYBE(e, result) {
auto exc = kj::Exception(kj::Exception::Type::FAILED, __FILE__, __LINE__,
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking nit: use KJ_EXCEPTION or JSG_KJ_EXCEPTION here?

Comment on lines 340 to 344
auto exc = kj::Exception(kj::Exception::Type::FAILED, __FILE__, __LINE__,
kj::str(JSG_EXCEPTION(Error), "connection attempt failed"));
resolveFulfiller(js, exc);
readable->getController().cancel(js, nullptr).markAsHandled(js);
writable->getController().abort(js, nullptr).markAsHandled(js);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: refactor into a function since the other handleProxyStatus has the same code

@a-robinson a-robinson force-pushed the arobinson/handle-proxy-status branch from 936c7a2 to be54eaa Compare August 9, 2023 14:38
@a-robinson
Copy link
Member Author

The fixup commit is here (posting since github doesn't appear to show it anymore): 936c7a2

So that I can handle initial connection errors on connections that were
established without using HTTP connect.
@a-robinson a-robinson force-pushed the arobinson/handle-proxy-status branch from be54eaa to de653b5 Compare August 9, 2023 14:47
@a-robinson a-robinson merged commit 7955dc4 into main Aug 9, 2023
7 checks passed
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.

4 participants