Commit ab00b687 authored by Kenton Varda's avatar Kenton Varda

Close idle HTTP connections on server drain.

Previously we only closed immediately after a response finished.
parent 97aad141
...@@ -3295,8 +3295,9 @@ public: ...@@ -3295,8 +3295,9 @@ public:
if (!firstRequest) { if (!firstRequest) {
// For requests after the first, require that the first byte arrive before the pipeline // For requests after the first, require that the first byte arrive before the pipeline
// timeout, otherwise treat it like the connection was simply closed. // timeout, otherwise treat it like the connection was simply closed.
firstByte = firstByte.exclusiveJoin( firstByte = firstByte
server.timer.afterDelay(server.settings.pipelineTimeout) .exclusiveJoin(server.timer.afterDelay(server.settings.pipelineTimeout)
.exclusiveJoin(server.onDrain.addBranch())
.then([this]() -> bool { .then([this]() -> bool {
timedOut = true; timedOut = true;
return false; return false;
...@@ -3328,8 +3329,9 @@ public: ...@@ -3328,8 +3329,9 @@ public:
if (firstRequest) { if (firstRequest) {
// On the first request, the header timeout starts ticking immediately upon request opening. // On the first request, the header timeout starts ticking immediately upon request opening.
receivedHeaders = receivedHeaders.exclusiveJoin( receivedHeaders = receivedHeaders
server.timer.afterDelay(server.settings.headerTimeout) .exclusiveJoin(server.timer.afterDelay(server.settings.headerTimeout)
.exclusiveJoin(server.onDrain.addBranch())
.then([this]() -> kj::Maybe<HttpHeaders::Request> { .then([this]() -> kj::Maybe<HttpHeaders::Request> {
timedOut = true; timedOut = true;
return nullptr; return nullptr;
...@@ -3352,6 +3354,10 @@ public: ...@@ -3352,6 +3354,10 @@ public:
// request is in-flight when we close... if it's a GET, the browser should retry. But if // request is in-flight when we close... if it's a GET, the browser should retry. But if
// it's a POST, retrying may be dangerous. This is why 408 exists -- it unambiguously // it's a POST, retrying may be dangerous. This is why 408 exists -- it unambiguously
// tells the client that it should retry.) // tells the client that it should retry.)
//
// Also note that if we ever decide to send 408 again, we might want to send some other
// error in the case that the server is draining, which also sets timedOut = true; see
// above.
return httpOutput.flush(); return httpOutput.flush();
} }
......
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