[
https://issues.apache.org/jira/browse/HTTPCORE-677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17341517#comment-17341517
]
Pierre N. commented on HTTPCORE-677:
------------------------------------
{code}
import org.apache.hc.core5.http.*;
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
import org.apache.hc.core5.http.io.HttpRequestHandler;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.protocol.HttpContext;
import java.io.IOException;
import java.net.InetAddress;
class Scratch {
public static void main(String[] args) throws Exception {
ServerBootstrap.bootstrap()
.setListenerPort(8888)
.register("*", (request, response, context) -> {
response.setEntity(new StringEntity("data"));
})
.setExceptionListener(new ExceptionListener() {
@Override
public void onError(Exception ex) {
ex.printStackTrace();
}
@Override
public void onError(HttpConnection connection, Exception ex) {
ex.printStackTrace();
}
})
.create()
.start();
Thread.sleep(100000L);
}
}
{code}
Make a request with curl or make a request with a browser like firefox or
chrome and close the browser. The following exception is always triggered :
{quote}
org.apache.hc.core5.http.ConnectionClosedException: Client closed connection
at
org.apache.hc.core5.http.impl.io.DefaultHttpRequestParser.createConnectionClosedException(DefaultHttpRequestParser.java:91)
at
org.apache.hc.core5.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:243)
at
org.apache.hc.core5.http.impl.io.DefaultHttpRequestParser.parse(DefaultHttpRequestParser.java:98)
at
org.apache.hc.core5.http.impl.io.DefaultHttpRequestParser.parse(DefaultHttpRequestParser.java:51)
at
org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection.receiveRequestHeader(DefaultBHttpServerConnection.java:135)
at
org.apache.hc.core5.http.impl.io.HttpService.handleRequest(HttpService.java:178)
at org.apache.hc.core5.http.impl.bootstrap.Worker.run(Worker.java:62)
at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
{quote}
What I suggest is not using an exception when the client is closing the
connection because it is expected at some point. Maybe creating a specific
ConnectionListener would be more approriate for this situation ? Of course, if
the client close the connection while the server is reading the header or the
request body, the exception is approriate, but that was not the case of my
example.
> Suggestion: Don't throw ConnectionClosedException when connection close is
> expected
> -----------------------------------------------------------------------------------
>
> Key: HTTPCORE-677
> URL: https://issues.apache.org/jira/browse/HTTPCORE-677
> Project: HttpComponents HttpCore
> Issue Type: Improvement
> Components: HttpCore
> Affects Versions: 5.1
> Reporter: Pierre N.
> Priority: Major
> Fix For: 5.1.1
>
>
> I'm testing apache core to replace Undertow in my web app so maybe I
> configured badly but I noticed the server is throwing an exception in
> ExceptionListener every time a client connection is closed.
> Is it necessary ? Is it really exceptional ? Do we really need to build a
> full stacktrace every time a socket is closed because it happens a lot.
> The connection is expected to be closed at some point, I understand an
> exception could be thrown if it occurs will reading the request or the
> request body, but if the request has been read, I think it is not exceptional
> and it shouldn't throw.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]