Skip to content

Commit

Permalink
Removed reliance on exception to shutdown non persistent connections (#…
Browse files Browse the repository at this point in the history
…12213)

Moved the shutdownOutput in HttpStreamOverHttp1 to before the continuation of handling
  • Loading branch information
gregw authored Aug 30, 2024
1 parent 1726c87 commit ebc5e55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ public void onFillable()
{
while (getEndPoint().isOpen())
{
if (LOG.isDebugEnabled())
LOG.debug("onFillable fill and parse {} {} {}", this, _httpChannel, _retainableByteBuffer);

// Fill the request buffer (if needed).
int filled = fillRequestBuffer();
if (LOG.isDebugEnabled())
LOG.debug("onFillable filled {} {} {} {}", filled, this, _httpChannel, _retainableByteBuffer);

if (filled < 0 && getEndPoint().isOutputShutdown())
close();

Expand Down Expand Up @@ -1523,12 +1523,17 @@ public void succeeded()
return;
}

// As this is not an upgrade, we can shutdown the output if we know we are not persistent
if (_sendCallback._shutdownOut)
getEndPoint().shutdownOutput();

_httpChannel.recycle();


// If a 100 Continue is still expected to be sent, but no content was read, then
// close the parser so that seeks EOF below, not the next request.
if (_expects100Continue)
{
// No content was read, and no 100 Continue response was sent.
// Close the parser so that below it seeks EOF, not the next request.
_expects100Continue = false;
_parser.close();
}
Expand All @@ -1541,7 +1546,6 @@ public void succeeded()
else
_parser.close();
}

_generator.reset();

// Can the onFillable thread continue processing
Expand All @@ -1552,9 +1556,6 @@ public void succeeded()
if (LOG.isDebugEnabled())
LOG.debug("non-current completion {}", this);

if (_sendCallback._shutdownOut)
getEndPoint().shutdownOutput();

// If we are looking for the next request
if (_parser.isStart())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public boolean handle(Request request, Response response, Callback callback)
}
});

try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
try (StacklessLogging ignored = new StacklessLogging(Response.class); Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();

Expand Down Expand Up @@ -233,7 +233,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
}
});

try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
try (StacklessLogging ignored = new StacklessLogging(Response.class); Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();

Expand Down Expand Up @@ -1669,12 +1669,10 @@ public void testWriteBodyAfterNoBodyResponse() throws Exception
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

String line = in.readLine();
System.err.println(line);
assertThat(line, containsString(" 304 "));
while (true)
{
line = in.readLine();
System.err.println(line);
if (line == null)
throw new EOFException();
if (line.length() == 0)
Expand All @@ -1685,7 +1683,6 @@ public void testWriteBodyAfterNoBodyResponse() throws Exception
assertThat(line, not(containsString("Transfer-Encoding")));
}

System.err.println("---");
line = in.readLine();
assertThat(line, containsString(" 304 "));
while (true)
Expand Down

0 comments on commit ebc5e55

Please sign in to comment.