Relogin session after request fail

Good day, I’m currently working on seemingly simple algorythm that sends requests in “during” loop and perform logout-login action if request failed. But Gatling acts strangely on any attempts to check if request failed.

Here is the code in current state:


exec(login)
.pause(login_lower,login_upper)
.during(duration, exitASAP = false) {
  tryMax(repeats){
    doIfEquals(session => session.status,KO) {
      println("\n\nIn the doIfEqueals\n\n")
      exec(logout)
        .exec(login)
    }
    .exec(request)
  }
  }.exitHereIfFailed
}.exec(logout)

After running this script Gatling prints "in the doIfEquals" before warmup and goes in after request fail and prints it again, but doesn't execute logout-login.

Tried many options like grabbing response code and comparing to 200, different locations of relogin, different condition operators, but no success for now.

Does anybody have any thoughts or advices regarding this situation?

Gatling version is 2.2.5, forgot to add at the beginning

At the moment I used following code with no tryMax:

doIfEquals(session => session.status,KO) {
  println("\n\nIn the doIfEqueals\n\n")
  exec(logout)
    .exec(login)
}

Aaand it "works" - after erquest is failed session perform relogin, but continues to relogin each iteration after a single fail.

Does any one have an idea how to make gatling relogin only once after each fail?