<div dir="ltr">Wow! Thanks for the super-fast reply.<div><br></div><div>I think I'm a little confused about the difference between being in an IO thread and being dispatched. Is it the case that if the server thinks I'm "not dispatched" (that is, if the server will send a response on my behalf when my method returns) that I'm always on an IO thread? I often do some work on my own thread pools and those threads often interact with the HttpServerExchange object. I know that some interactions with the exchange object (e.g. recieveFullBytes) will take an exchange that is in a dispatched state and put it in a non-dispatched state. So I want to just keep checking that I'm dispatched and, if I'm not, dispatch again. So my code might look something like:</div><div><br></div><div>void handle(HttpServerExchange exchange) {</div><div> exchange.dispatch(myOwnThreadPoolExecutor, () -> {</div><div> <a href="http://log.info">log.info</a>("I am not not on an IO thread and I am dispatched.");</div><div> doSomethingWithExchange(exchange);</div><div> assert exchange.isDispatched();</div><div> assert !exchange.isInIoThread();</div><div> // how do I check to see if I'm still in a dispatched state?</div><div> });</div><div>}</div><div><br></div><div>(note: the above is a bad, super-simplified example and in the actual code there's a lot of asynchronous stuff happening that bounces the execution from one thread pool to another).</div><div><br></div><div>The reason for all of this is that I have some edge cases which appear to be race conditions in which I know for sure that I call exchange.dispatch() and then I start doing some work but the exchange gets ended before I've finished my computations and have a response to send leaving the client with an empty response. I'm not entirely sure how that could happen, but my best guess right now is that I interact with the exchange in some way that causes it to no longer be in in the dispatched state and, as a result, the HttpServerExchange is ending the exchange for me before I'm ready.</div><div><br></div><div>Thanks again,<br>Oliver</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 22, 2016 at 12:47 PM Stuart Douglas <<a href="mailto:sdouglas@redhat.com">sdouglas@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">After the call stack returns and the dispatch actually happens<br class="gmail_msg">
isDispatched() will return false (allowing the exchange to be<br class="gmail_msg">
dispatched again).<br class="gmail_msg">
<br class="gmail_msg">
In general you should not really need to check this anyway, if you<br class="gmail_msg">
want to know if you are in the IO thread you should use isInIiThread()<br class="gmail_msg">
instead.<br class="gmail_msg">
<br class="gmail_msg">
Stuart<br class="gmail_msg">
<br class="gmail_msg">
On Wed, Nov 23, 2016 at 7:44 AM, Oliver Dain <<a href="mailto:oliver@analyticspot.com" class="gmail_msg" target="_blank">oliver@analyticspot.com</a>> wrote:<br class="gmail_msg">
> I've got some pretty simple code that looks something like:<br class="gmail_msg">
><br class="gmail_msg">
> if (!exhange.isDispatched()) {<br class="gmail_msg">
> exchange.dispatch(() -> {<br class="gmail_msg">
> assert exchange.isDispatched();<br class="gmail_msg">
> // more stuff....<br class="gmail_msg">
> });<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> but the assert fails. That is, when dispatch calls my runnable isDispatched<br class="gmail_msg">
> is not true.<br class="gmail_msg">
><br class="gmail_msg">
> I believe I have a bug somewhere with how/when dispatches are happening so<br class="gmail_msg">
> I've littered my code with such asserts and they fail reliably even when I'm<br class="gmail_msg">
> quite sure the exchange has been dispatched (e.g. when it is literally the<br class="gmail_msg">
> first call in a Runnable passed to to the dispatch() method).<br class="gmail_msg">
><br class="gmail_msg">
> What am I doing wrong?<br class="gmail_msg">
> --<br class="gmail_msg">
> CTO, Analytic Spot<br class="gmail_msg">
> 44 West Broadway #222<br class="gmail_msg">
> Eugene, OR 97401<br class="gmail_msg">
> <a href="http://analyticspot.com" rel="noreferrer" class="gmail_msg" target="_blank">analyticspot.com</a> • <a href="tel:(425)%20296-6556" value="+14252966556" class="gmail_msg" target="_blank">425-296-6556</a><br class="gmail_msg">
> <a href="http://www.linkedin.com/in/oliverdain" rel="noreferrer" class="gmail_msg" target="_blank">www.linkedin.com/in/oliverdain</a><br class="gmail_msg">
><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> undertow-dev mailing list<br class="gmail_msg">
> <a href="mailto:undertow-dev@lists.jboss.org" class="gmail_msg" target="_blank">undertow-dev@lists.jboss.org</a><br class="gmail_msg">
> <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br class="gmail_msg">
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div style="font-size:small"><div style="font-size:13px;line-height:19.5px">CTO, Analytic Spot</div><div style="font-size:13px;line-height:19.5px">44 West Broadway #222</div><div style="font-size:13px;line-height:19.5px">Eugene, OR 97401<br></div><div style="font-size:13px;line-height:19.5px"><a href="http://analyticspot.com/" style="z-index: 0;">analyticspot.com</a> <span style="color:rgb(127,127,127);font-family:'helvetica neue';font-size:11px;line-height:normal">• </span>425-296-6556</div></div><div style="font-size:small"><span style="line-height:19.5px"><a href="http://www.linkedin.com/in/oliverdain" style="z-index: 0;">www.linkedin.com/in/oliverdain</a></span></div></div></div>