Intended way of shutting down resources

Hi,

i struggle how to shut down resources which i need during my scenario. According to the documentation i should use “before” and “after” methods.

Let’s imagine that i create a ssh proxy tunnel with my “before” method and the scenario action itself will create a TCP connection towards my tunnel. If i look at the kafka gatling extension, the extension registers the shutdown of the TCP connection within the ActionBuilder with the akka system shutdown: https://github.com/mnogu/gatling-kafka/blob/master/src/main/scala/com/github/mnogu/gatling/kafka/action/KafkaRequestActionBuilder.scala#L22

What is the architectural intended way for this scenario, because the “after” method will always get executed first and then the TCP connection will get closed with the shutdown of the scenario. Since the connection is already gone, this will throw an exception.

Is the Kafka extension doing it wrong or on the wrong location (e.g. like this: https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/protocol/JmsProtocol.scala#L37)?
Is there any known way how to get the ActorSystem within my scenario, so i’m able to register shutdown methods there as well?

Best Regards
Hajo