Awesome, thanks!<br><br><div>Piotr</div><br><div class="gmail_quote">On Thu Dec 04 2014 at 3:06:07 AM Stuart Douglas <<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I created a JIRA:<br>
<br>
<a href="https://issues.jboss.org/browse/UNDERTOW-349" target="_blank">https://issues.jboss.org/<u></u>browse/UNDERTOW-349</a><br>
<br>
Fix is upstream, will be in release of 1.1.2.Final and 1.2.0.Beta7.<br>
<br>
Stuart<br>
<br>
----- Original Message -----<br>
> From: "Piotr Betkier" <<a href="mailto:pbetkier@gmail.com" target="_blank">pbetkier@gmail.com</a>><br>
> To: <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
> Sent: Thursday, 4 December, 2014 9:12:25 AM<br>
> Subject: [undertow-dev] Unexpected RequestLimitingHandler behavior after queue gets full<br>
><br>
> Hello,<br>
><br>
> I wanted to introduce a constraint on the number of requests my server tries<br>
> to handle at a time and played around with RequestLimitingHandler a little<br>
> bit. However, I observed unexpected behavior once RequestLimit's queue gets<br>
> full.<br>
><br>
> I've created a RequestLimitingHandler with both maximumConcurrentRequests and<br>
> queueSize set to 1 and nextHandler that responds after a 3 second sleep.<br>
> This is what I observed:<br>
><br>
> When I sent 2 concurrent requests with a curl, I got the first response after<br>
> 3 seconds and the second one after 6 - just as expected, the second request<br>
> got queued.<br>
><br>
> When I sent 3 concurrent requests, I got two correct responses and one 513 -<br>
> just as expected, my third request couldn't fit into the queue so a failure<br>
> handler got called.<br>
><br>
> Now it got tricky - this made RequestLimit enter an invalid state, where its<br>
> "state" field got decremented below the value that represents 0 current<br>
> requests. Now "state & MASK_CURRENT" gives 2147483647 instead of 0, so the<br>
> next time I make a single request, RequestLimit thinks there are 2147483647<br>
> requests in the system currently and queues my request instead of handling<br>
> it. Then I make yet another request and now the queue is full, so 513 error<br>
> is generated instantly which in turn makes RequestLimit poll my first<br>
> pending request from the queue and dispatch it for handling. RequestLimit<br>
> got corrupted and is unusable from now on.<br>
><br>
> I hope I explained my observations clearly. Is there something wrong in my<br>
> setup, my understanding of Undertow or it's a bug? This is my code snippet,<br>
> tested with undertow 1.1.0.Final and 1.2.0.Beta5:<br>
><br>
> import io.undertow.Undertow;<br>
> import io.undertow.server.<u></u>HttpHandler;<br>
> import io.undertow.server.<u></u>HttpServerExchange;<br>
> import io.undertow.server.handlers.<u></u>RequestLimitingHandler;<br>
> import io.undertow.util.Headers;<br>
><br>
> public class Main {<br>
><br>
> public static void main(String[] args) {<br>
> Undertow server = Undertow.builder()<br>
> .addHttpListener(8080, "localhost")<br>
> .setHandler(new RequestLimitingHandler(1, 1, handler()))<br>
> .build();<br>
><br>
> server.start();<br>
> }<br>
><br>
> private static HttpHandler handler() {<br>
> return new HttpHandler() {<br>
> @Override<br>
> public void handleRequest(final HttpServerExchange exchange) throws Exception<br>
> {<br>
> Thread.sleep(3000);<br>
> exchange.getResponseHeaders().<u></u>put(Headers.CONTENT_TYPE, "text/plain");<br>
> exchange.getResponseSender().<u></u>send("Hello World");<br>
> }<br>
> };<br>
> }<br>
><br>
> }<br>
><br>
><br>
> Cheers,<br>
> Piotr<br>
><br>
><br>
> ______________________________<u></u>_________________<br>
> undertow-dev mailing list<br>
> <a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/undertow-dev</a><br>
</blockquote></div>