-
Notifications
You must be signed in to change notification settings - Fork 335
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
Refactors Sockets closed promise handling. #237
Conversation
ca3d4fa
to
f79c885
Compare
a5277b5
to
171059b
Compare
Last push was a rebase. Ready for another review |
Please note my reply to a previous thread (which had been marked resolved): #237 (comment) |
@kentonv responded. |
171059b
to
fc8da39
Compare
Rebased |
fc8da39
to
46c7aa2
Compare
Ready for review. |
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.
LGTM but let's also have @kentonv or @harrishancock review and sign off.
46c7aa2
to
b315ad3
Compare
Rebased |
b315ad3
to
3979484
Compare
// better way? | ||
auto& context = IoContext::current(); | ||
return context.awaitIo(kj::mv(closeFulfiller->promise)); | ||
jsg::MemoizedIdentity<jsg::Promise<void>>& getClosed() { |
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.
It looks like, at present, this promise is only resolved when the application calls close()
explicitly -- not when the remote side disconnects. Is that correct?
If so, it seems like it's not accomplishing a whole lot to offer a way to listen for closure. The application can set that up itself and save us the trouble. So I'd remove getClosed()
in that case.
If the intent is that this promise should also tell the application when the remote end disconnects the socket, then I think you should add code that listens on whenWriteDisconnected()
and fulfills the promise at that point. (Or maybe it should wait on both whenWriteDisconnected()
and EOF or error on the read side, and only resolve when both are true... I'm not really sure... I'd be satisfied with waiting for whenWriteDisconnected()
only.)
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.
Yep, it's the current behaviour in workerd HEAD as well. I split this PR off from #205 to not block on this and instead focus on the refactoring.
I will follow up on this but first we need to decide how we want the semantics to work exactly.
c4c410b
to
f71e02a
Compare
resolveFulfiller(nullptr); | ||
return js.resolvedPromise(); | ||
}, [this](jsg::Lock& js, jsg::Value err) { return errorHandler(js, kj::mv(err)); }); | ||
}, [this](jsg::Lock& js, jsg::Value err) { return errorHandler(js, kj::mv(err)); }); |
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.
So it looks like any exceptions caught from cancel()
or abort()
propagate to the closed
promise, but do NOT propagate to the result of close()
itself.
Is that what we want? I'm not really sure when cancel()
or abort()
would throw, but it would seem to me that the exception should propagate out of close()
. Meanwhile it's not clear to me whether the closed
promise should signal errors or just signal that the socket is now closed.
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.
Well, I'd allow the error to propagate to the closed
promise but I would explicitly mark it handled using markAsHandled
so that if someone isn't paying attention it's perfectly ok.
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.
Meanwhile it's not clear to me whether the closed promise should signal errors or just signal that the socket is now closed.
It's not clear to me either. Though I trust James' opinion here.
This is another case that I think we need to discuss in more depth. I want us to do so on this issue and many others, after discussion we may end up with another decision (especially if we decide to conform to other specs) so let's not worry too much about making it perfect in this PR.
f71e02a
to
32a91b6
Compare
@dom96 ... PR needs a rebase. |
32a91b6
to
ca99307
Compare
This is a more basic version of #205. The main change in semantics here is that the
closed
promise will now have any errors propagated to it (from the readable/writable stream close calls). The rest is a major refactor to reuse the existingnewPromisedStream
.Test Plan