How to deal with "Response is closed", due to client cancelling

2,773 views
Skip to first unread message

Alexis Hassler

unread,
Mar 19, 2018, 4:24:17 AM3/19/18
to vert.x
When a client like a browser cancels its request, it closes the HTTP response.
And when I call response.end(), I'm getting this error :

java.lang.IllegalStateException: Response is closed
    at io
.vertx.core.http.impl.HttpServerResponseImpl.checkValid(HttpServerResponseImpl.java:547)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end0(HttpServerResponseImpl.java:400)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:318)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:307)
    at fr
.sewatech.vertx.HttpVerticle.lambda$response$8(HttpVerticle.java:75)

As I don't want to see clients canceling requests as errors in my logs, I would like to deal with this errors in a better way.

For now, the only solution that I found is to check whether the response is closed before the end() :

if (!response.closed())
    response
.end();

Adding if here and there is not my favorite way of coding.
Is there a better way to do it ?

Thomas SEGISMONT

unread,
Mar 19, 2018, 6:33:03 AM3/19/18
to ve...@googlegroups.com
Someone in the community already commented there that the solution could be inconvenient.
Perhaps you could second that comment?

I can't think of a better way than what you described.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/98254441-b78e-464f-80e2-47686a8631dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Thomas SEGISMONT

unread,
Mar 20, 2018, 4:28:04 PM3/20/18
to ve...@googlegroups.com


2018-03-19 12:00 GMT+01:00 Alexis Hassler <alexis....@gmail.com>:
Thanks Thomas,

Now I don't feel alone ;)

I think that with a router, I'll be able to make better code.
I'll add an failureHandler that will catch this kind of exception.

+1 great idea
 

Le lundi 19 mars 2018 11:33:03 UTC+1, Thomas Segismont a écrit :
Someone in the community already commented there that the solution could be inconvenient.
Perhaps you could second that comment?

I can't think of a better way than what you described.
2018-03-19 9:24 GMT+01:00 Alexis Hassler <alexis....@gmail.com>:
When a client like a browser cancels its request, it closes the HTTP response.
And when I call response.end(), I'm getting this error :

java.lang.IllegalStateException: Response is closed
    at io
.vertx.core.http.impl.HttpServerResponseImpl.checkValid(HttpServerResponseImpl.java:547)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end0(HttpServerResponseImpl.java:400)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:318)
    at io
.vertx.core.http.impl.HttpServerResponseImpl.end(HttpServerResponseImpl.java:307)
    at fr
.sewatech.vertx.HttpVerticle.lambda$response$8(HttpVerticle.java:75)

As I don't want to see clients canceling requests as errors in my logs, I would like to deal with this errors in a better way.

For now, the only solution that I found is to check whether the response is closed before the end() :

if (!response.closed())
    response
.end();

Adding if here and there is not my favorite way of coding.
Is there a better way to do it ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

Julien Viet

unread,
Mar 21, 2018, 4:20:50 AM3/21/18
to ve...@googlegroups.com
yes that should be the recommended way , most users are using vertx-web and it's a good practice to have a failure handler for most situations

Mike Wiesenberg

unread,
Apr 11, 2019, 7:23:36 AM4/11/19
to vert.x
How does adding a failureHandler prevent the exception from being thrown/logged? Based on my testing it does not.
To unsubscribe from this group and stop receiving emails from it, send an email to ve...@googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ve...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages