[undertow-dev] Question about endExchange() and response Sender

Stuart Douglas sdouglas at redhat.com
Mon Mar 19 19:42:36 EDT 2018


On Tue, Mar 20, 2018 at 12:23 AM, Mario Carbajal <mario.e.carbajal at gmail.com
> wrote:

> In a dispatched non-blocking HttpRequest handler I'm calling endExchange
> immediately after calling send on the response Sender. I am unsure if this
> will cause the sender to be interrupted or if the exchange will end only
> after the sender is done writing the data.
>

Don't do that. It will appear to work for short responses where the data
can be written out in a single write() call, but if it needs to be written
out by the IO thread the data will be truncated.

Once the send is completed the sender will call endExchange for you, there
is no need to do it yourself (assuming you are using the version that does
not take a completion callback, the default callback just calls
endExchange. If you are using a callback you will need to end it yourself).

Stuart


> The code looks like this:
>
> @Override
> public void handleRequest(HttpServerExchange exchange) throws Exception
> {
>     if (exchange.isInIoThread()) {
>         exchange.dispatch(this);
>         return;
>     }
>
>     try {
>         ... do things ...
>         exchange.getResponseSender().send(data);
>     }finally {
>         exchange.endExchange();
>     }
> }
>
>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20180320/11bb22e4/attachment-0001.html 


More information about the undertow-dev mailing list