Session attribute is not clean up

Here is how I usually set up my scenario:

val scn = scenario(“Flow”).forever {
exitBlockOnFail {
exec(request_1).exec(request_2)
}
}

setUp(
scn.inject(rampUsers(sessions) over(rampUp seconds)))
.protocols(httpConf)
.maxDuration(durationMinutes minutes)

So the test will repeat and run for durationMinutes. However, I found that if I set a session attribute, the attribute is still in the session after the session finishes. That makes all my _.contains(“attribute”) checks fail.

Is there a way to clean up all the session attributes set during the session? Or is there any problem with my scenario set up?

Thanks
Brian

However, I found that if I set a session attribute, the attribute is still in the session after the session finishes.

The sentence doesn’t make sense.
When a Session finishes, you can no longer access it, and it’s garbaged collected.

Then, of course, you’re the one in charge of cleaning the Sessions if you store too much data and cause GC pressure.

I think the problem is how I set up the scenario. After I made all the requests, I have a forever loop that goes back to the top and make the list of requests again. The session doesn’t actually finish from Gatling’s perspective.

So what is a proper way to set up my scenario? Each session should properly finish when all the requests are made, and I want to keep a constant active sessions throughout the test.

Are you sure you want a close model (= recycling users). This kind of model only match some very specific use cases, eg call centers.
You should probably use an open model and create new users.

If you really want to recycle your users (which is, I insist, probably wrong and just some bad habit you have from some other tool), you have to indeed clean them:

exec(session => session.copy(attributes = Map.empty)))

Thank you for your advise. I will discuss with my colleagues to figure out the best practice for our use case.