Commit 3fcd0f46 authored by Kenton Varda's avatar Kenton Varda

WebSocket pump() should end at Close message.

This reverts the core change from: https://github.com/capnproto/capnproto/commit/6e4c5ce3c9f31a5e79b50cd9eaae6d03106edf98

There are a few reasons to believe that change was wrong:
- It meant that a pump would always throw and catch a DISCONNECTED exception, which violates the rule that we don't throw exceptions in "normal" operation.
- It could lead to trouble when combined with the previous commit, which could delay WebSocket disconnect until the service "completes" -- which would lead to a hang.

The commit message where I introduced this said something about bad behavior on OSX. We should address that directly, if it is still a problem.
parent 90d48343
......@@ -1459,7 +1459,7 @@ KJ_TEST("HttpInputStream responses") {
KJ_CONTEXT(testCase.raw);
KJ_ASSERT(input->awaitNextMessage().wait(waitScope));
auto resp = input->readResponse(testCase.method).wait(waitScope);
KJ_EXPECT(resp.statusCode == testCase.statusCode);
KJ_EXPECT(resp.statusText == testCase.statusText);
......@@ -2610,13 +2610,6 @@ KJ_TEST("newHttpService from HttpClient WebSockets") {
.then([&]() { return backPipe.ends[1]->write({WEBSOCKET_REPLY_MESSAGE}); })
.then([&]() { return expectRead(*backPipe.ends[1], WEBSOCKET_SEND_CLOSE); })
.then([&]() { return backPipe.ends[1]->write({WEBSOCKET_REPLY_CLOSE}); })
// expect EOF
.then([&]() { return backPipe.ends[1]->readAllBytes(); })
.then([&](kj::ArrayPtr<byte> content) {
KJ_EXPECT(content.size() == 0);
// Send EOF.
backPipe.ends[1]->shutdownWrite();
})
.eagerlyEvaluate([](kj::Exception&& e) { KJ_LOG(ERROR, e); });
{
......
......@@ -2484,9 +2484,9 @@ static kj::Promise<void> pumpWebSocketLoop(WebSocket& from, WebSocket& to) {
.then([&from,&to]() { return pumpWebSocketLoop(from, to); });
}
KJ_CASE_ONEOF(close, WebSocket::Close) {
// Once a close has passed through, the pump is complete.
return to.close(close.code, close.reason)
.attach(kj::mv(close))
.then([&from,&to]() { return pumpWebSocketLoop(from, to); });
.attach(kj::mv(close));
}
}
KJ_UNREACHABLE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment