java.lang.IllegalStateException when doing any check on response body

Hi All,
I am using gatling-sbt version - 2.1.7. When I use any kind of check on response body, it gives the below error when running with more than 1 users and when running multiple simulation files (One after the other)

java.lang.IllegalStateException: Current state = CODING, new state = FLUSHED

at java.nio.charset.CharsetDecoder.throwIllegalStateException(CharsetDecoder.java:992) ~[na:1.8.0_60]

at java.nio.charset.CharsetDecoder.flush(CharsetDecoder.java:675) ~[na:1.8.0_60]

at io.gatling.http.util.BytesHelper$$anonfun$byteBuffersToString$1.apply(BytesHelper.scala:80) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.util.BytesHelper$$anonfun$byteBuffersToString$1.apply(BytesHelper.scala:74) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at scala.collection.Iterator$class.foreach(Iterator.scala:743) ~[scala-library-2.11.4.jar:na]

at scala.collection.AbstractIterator.foreach(Iterator.scala:1195) ~[scala-library-2.11.4.jar:na]

at io.gatling.http.util.BytesHelper$.byteBuffersToString(BytesHelper.scala:74) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.util.BytesHelper$.byteBufsToString(BytesHelper.scala:58) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.response.StringResponseBody$.apply(ResponseBody.scala:59) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.response.ResponseBuilder.build(ResponseBuilder.scala:189) ~[gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.ahc.AsyncHandler.onCompleted(AsyncHandler.scala:115) [gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at io.gatling.http.ahc.AsyncHandler.onCompleted(AsyncHandler.scala:47) [gatling-http-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]

at org.asynchttpclient.netty.NettyResponseFuture.getContent(NettyResponseFuture.java:173) [async-http-client-2.0.0-alpha13.jar:na]

at org.asynchttpclient.netty.NettyResponseFuture.done(NettyResponseFuture.java:210) [async-http-client-2.0.0-alpha13.jar:na]

at org.asynchttpclient.netty.handler.HttpProtocol.finishUpdate(HttpProtocol.java:195) [async-http-client-2.0.0-alpha13.jar:na]

at org.asynchttpclient.netty.handler.HttpProtocol.handleChunk(HttpProtocol.java:461) [async-http-client-2.0.0-alpha13.jar:na]

at org.asynchttpclient.netty.handler.HttpProtocol.handle(HttpProtocol.java:483) [async-http-client-2.0.0-alpha13.jar:na]

at org.asynchttpclient.netty.handler.Processor.channelRead(Processor.java:85) [async-http-client-2.0.0-alpha13.jar:na]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [netty-codec-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244) [netty-codec-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:147) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [netty-transport-4.0.31.Final.jar:4.0.31.Final]

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) [netty-common-4.0.31.Final.jar:4.0.31.Final]

at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [netty-common-4.0.31.Final.jar:4.0.31.Final]

at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

Both of my simulation files are using some checks on response body as shown below. They are not using any feeders, I have the made the simulation very simple to get to the actual issue. When I comment all the checks on response body, then I don’t get the above error. Can anybody tell me why I get this error and how to use checks on response body without any errors?

exec(

http(“Get Business Rule Scripts”)

.get(ruleScript + “5452462dae60ffd54100009b”)

.headers(getHeaders)

.check(status is 200)

.check(jsonPath("$._id").saveAs(“id”))

.check(regex(“symbols.notifications.push”).exists)

.check(regex(“Hello”).exists)

.check(bodyString.saveAs(“responseBody”)) )

.exec(session => {

println("Response Body: "+ session(“responseBody”).as[String])

session })

Fixed, thanks for reporting!
https://github.com/gatling/gatling/commit/a27fe8372de3b0855fa5742cd8dbc9cff093ba68

Note that master is currently going under major internal changes (building AsyncHttpClient 2 and switching to Netty 4), so such regressions can sadly happen.
Having volunteers to give it a try and provide some feedback is a great help!

Cheers,

Thanks Stephane!