[undertow-dev] how to implement request processing timeout

Stuart Douglas sdouglas at redhat.com
Sun Jul 15 22:45:26 EDT 2018


On Mon, Jul 16, 2018 at 12:16 PM Stan Rosenberg <stan.rosenberg at gmail.com>
wrote:

> On Sun, Jul 15, 2018 at 9:48 PM, Stuart Douglas <sdouglas at redhat.com>
> wrote:
>
>> If all you want to do is drop the connection then just scheduling a task
>> that does exchange.getConnection().close() is fine, no HTTP response will
>> be returned to the client.
>>
>
> That would imply exchange.getConnection().close() is thread-safe; just
> double-checking.
>

Yes.


>
>
>>
>> If you want to actually send a response to the client then you are going
>> to have to have some kind of lock/CAS that prevents your application from
>> writing once the timeout has taken effect.
>>
>>
> ​Makes sense, but that's custom logic; i.e., not available in the API,
> right?
>

Yes. The issue with including something like this in the core API is that
every request has to pay the thread safety price even if they don't use it.


>
> Are you using the Servlet API or the HttpServerExchange API? The best way
>> to approach this is a bit different depending on what you are doing.
>>
>
>  HttpServerExchange API
> ​. Thanks!​
>

This is a bit harder to do in the general case. With Servlet you could just
create a thread safe wrapper, where the wrapper basically disconnects from
the underlying request on timeout. The Undertow native API is not designed
around wrapping though, so it needs cooperation from the application to
manage this.

If you know the application is only going to be writing data (and not
setting headers) then you should be able to make this work via a
ConduitFactory implementation that handles the locking, although if this is
not the case then you are going to need some kind of external lock.

Stuart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20180716/801bd311/attachment.html 


More information about the undertow-dev mailing list