# Using during in a foreach loop

**URL:** <https://community.gatling.io/t/using-during-in-a-foreach-loop/3132>\
**Category:** Gatling (Open-Source)\
**Created:** [July 13, 2016, 7:21am UTC](https://community.gatling.io/t/using-during-in-a-foreach-loop/3132 "2016-07-13T07:21:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Valsecchi](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@Patrick\_Valsecchi](https://community.gatling.io/u/Patrick_Valsecchi)\
**Post date:** [July 13, 2016, 7:21am UTC](https://community.gatling.io/t/using-during-in-a-foreach-loop/3132/1 "2016-07-13T07:21:58Z")

</div>

Hi,

I’m trying to use Gatling (V2.2.2) to compare the perfs of multiple map servers at different zoom levels with different number of users. So basically, my scenario looks like that:

```auto
val scn = scenario("User").group(_ => PerfConfig.nbUsers.toString) {
  foreach(PerfConfig.baseUrls, "base_url") {
    group(session => PerfConfig.baseUrlMap(session("base_url").as[String])) {
      foreach(steps.reverse, "level") {
        exec(session => {
          println("Starting level " + session("level").as[String])
          session
        })
          .during(30 seconds) {
            exec(session => PerfConfig.addRandomTileInfo(session)).exec(fetchTile)
          }
          .exec(session => {
            println("Done level " + session("level").as[String])
            session
          })
      }
    }
  }
}

```

The full code can be found there:  
[https://github.com/pvalsecc/ms\_perfs/tree/master/perfs/com/camptocamp](https://github.com/pvalsecc/ms_perfs/tree/master/perfs/com/camptocamp)

My problem is that after the first iteration of “during” is done, I have multiple un-wanted behaviors:

- “Done level 7” is printed a lot of times (one for each fetchTile execution, I guess). I don’t see why this is like that since it is done after the “during” loop. I’ve tried to put the “during” inside an exec by itself, but it didn’t help.
- Gatling freezes and doesn’t do anymore query. It just prints the summary report every 5 seconds with no new query in it.

It’s not possible to chain a “during” with other stuff to do after?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 13, 2016, 9:12am UTC](https://community.gatling.io/t/using-during-in-a-foreach-loop/3132/2 "2016-07-13T09:12:41Z")

</div>

Hi,

Could you please provide a runnable reproducer, please?  
[This similar sample](https://gist.github.com/slandelle/cc11d1af91426c86455bd1f5b0452573) works fine for me.

---

<div class="post-metadata">

**Author:** ![Patrick\_Valsecchi](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@Patrick\_Valsecchi](https://community.gatling.io/u/Patrick_Valsecchi)\
**Post date:** [July 13, 2016, 12:31pm UTC](https://community.gatling.io/t/using-during-in-a-foreach-loop/3132/3 "2016-07-13T12:31:43Z")

</div>

Stéphane,

I’ve tried your reproducer and it works fine with gatling 2.2.1 (with the denvazh/gatling:2.2.1 docker image). With 2.2.2 (with the denvazh/gatling:2.2.2 docker image) it goes mad and outputs that:  
gatling\_1 | attr1=1 attr2=1  
gatling\_1 | Loop Done  
gatling\_1 | Loop Done

… (tons of them)  
gatling\_1 | 12:24:24.756 [ERROR] a.a.ActorSystemImpl - Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-4] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled  
gatling\_1 | java.lang.StackOverflowError: null  
gatling\_1 | at sun.nio.cs.UTF\_8.updatePositions(UTF\_8.java:77)  
gatling\_1 | at sun.nio.cs.UTF\_8.access$200(UTF\_8.java:57)  
gatling\_1 | at sun.nio.cs.UTF\_8$Encoder.encodeArrayLoop(UTF\_8.java:636)  
gatling\_1 | at sun.nio.cs.UTF\_8$Encoder.encodeLoop(UTF\_8.java:691)  
gatling\_1 | at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:579)  
gatling\_1 | at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:271)  
gatling\_1 | at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)  
gatling\_1 | at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)  
gatling\_1 | at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)  
gatling\_1 | at java.io.PrintStream.write(PrintStream.java:526)  
gatling\_1 | at java.io.PrintStream.print(PrintStream.java:669)  
gatling\_1 | at java.io.PrintStream.println(PrintStream.java:823)  
gatling\_1 | at scala.Console$.println(Console.scala:148)  
gatling\_1 | at scala.Predef$.println(Predef.scala:315)  
gatling\_1 | at com.camptocamp.ComplexLoopSimulation$$anonfun$2.apply(ComplexLoopSimulation.scala:26)  
gatling\_1 | at com.camptocamp.ComplexLoopSimulation$$anonfun$2.apply(ComplexLoopSimulation.scala:25)  
gatling\_1 | at io.gatling.core.action.SessionHook.execute(SessionHook.scala:38)  
gatling\_1 | at io.gatling.core.action.BlockExit.exitBlock(BlockExit.scala:37)  
gatling\_1 | at io.gatling.core.action.BlockExit$.noBlockExitTriggered(BlockExit.scala:122)  
gatling\_1 | at io.gatling.core.action.Loop.execute(Loop.scala:52)  
gatling\_1 | at io.gatling.core.action.Action$class.$bang(Action.scala:35)  
gatling\_1 | at io.gatling.core.action.Loop.$bang(Loop.scala:36)  
gatling\_1 | at [io.gatling.core.action.SessionHook.io](http://io.gatling.core.action.SessionHook.io)$gatling$core$action$SessionHook$$$anonfun$1(SessionHook.scala:38)  
gatling\_1 | at io.gatling.core.action.SessionHook$lambda$$execute$1.apply(SessionHook.scala:38)  
gatling\_1 | at io.gatling.core.action.SessionHook$lambda$$execute$1.apply(SessionHook.scala:38)  
gatling\_1 | at io.gatling.commons.validation.Success.map(Validation.scala:32)  
gatling\_1 | at io.gatling.core.action.SessionHook.execute(SessionHook.scala:38)  
gatling\_1 | at io.gatling.core.action.BlockExit.exitBlock(BlockExit.scala:37)  
gatling\_1 | at io.gatling.core.action.BlockExit$.noBlockExitTriggered(BlockExit.scala:122)

… (smells like an infinite recusion)

With 2.2.1, my stuff works fine. So, looks like a bug within the 2.2.2 image.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 13, 2016, 12:57pm UTC](https://community.gatling.io/t/using-during-in-a-foreach-loop/3132/4 "2016-07-13T12:57:16Z")

</div>

You’re running into [https://github.com/gatling/gatling/issues/3060](https://github.com/gatling/gatling/issues/3060), which is already fixed.  
Use the snapshot for now.
