I'm getting the following exception when I run an integration test, but only sometimes:

HttpServerExchange cannot have both async IO resumed and dispatch() called in the same cycle

So clearly I've got some kind of race condition where sometimes I'm doing things in an odd order, but I can't figure out where. Part of the issue is that the above error doesn't include a stack trace so it's hard for me to tell where it is in the code when this happens. Is there a way to get a stack trace?

Also, I'm calling "exchange.setResponseCookie" after having called dispatch but before ending the exchange. That should be safe, right? It's the only thing I can think of. As far as I can tell, what happens is the request comes in, a few handlers examine the request, but those are read-only operations for logging and such, then then dispatch to a wrapped handler. Finally get to our inner-most handler which calls dispatch. That then does some async work (a lookup in a database) and, when it's complete it sets a few cookies. After that the response is put on the exchange via "exchange.getResponseSender().send". Finally a few things listen for the exchange to complete so they can log some things but these are again calling read-only properties like "exchange.getStatusCode()", "exchange.getResponseBytesSent()", and "exchange.getResponseCookies().keySet())". Any ideas what might be causing this error?

thanks,
Oliver
--
CTO, Analytic Spot
44 West Broadway #222
Eugene, OR 97401
analyticspot.com • 425-296-6556
www.linkedin.com/in/oliverdain