# JMS Simulation does not shutdown after successful run

**URL:** <https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338>\
**Category:** Gatling (Open-Source)\
**Created:** [June 4, 2015, 9:43am UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338 "2015-06-04T09:43:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Oudmaijer](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephan\_Oudmaijer](https://community.gatling.io/u/Stephan_Oudmaijer)\
**Post date:** [June 4, 2015, 9:43am UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/1 "2015-06-04T09:43:44Z")

</div>

Hi,

we have a simulation that does jms reqreply against Oracle AQ. The simulation runs just fine, but at the end it does not terminate properly and keeps hanging during shutdown (every time we run the simulation).

What is a correct way of forcing the simulation to terminate after is has succeeded?

Regards, Stephan

---

<div class="post-metadata">

**Author:** ![Stephan\_Oudmaijer](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephan\_Oudmaijer](https://community.gatling.io/u/Stephan_Oudmaijer)\
**Post date:** [June 5, 2015, 12:57pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/2 "2015-06-05T12:57:00Z")

</div>

I have figured out why it is not shutting down. We use Oracle AQ. The simulation terminates but for some reason the ConnectionFactory is not closed and there are session to the database still open.

Now I have to figure out how to fix it.

---

<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:** [June 5, 2015, 1:12pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/3 "2015-06-05T13:12:28Z")

</div>

Mmmm, except if it’s something specific to Oracle AQ, you don’t close a ConnectionFactory, it’s just a factory.

We automatically close the producer, the session and the connection + the listener threads.  
[https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/client/SimpleJmsClient.scala#L156-L158](https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/client/SimpleJmsClient.scala#L156-L158)

[https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/action/JmsReqReplyAction.scala#L92](https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/action/JmsReqReplyAction.scala#L92)

You should monitor and check which threads are still alive exactly.

---

<div class="post-metadata">

**Author:** ![Stephan\_Oudmaijer](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephan\_Oudmaijer](https://community.gatling.io/u/Stephan_Oudmaijer)\
**Post date:** [June 5, 2015, 1:58pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/4 "2015-06-05T13:58:13Z")

</div>

After digging a bit deeper into the JmsReqReplyAction it looks like the postStop() hangs on closing the listenerThreads.

```auto
override def postStop(): Unit = {
  listenerThreads.foreach(_.close())
  client.close()
}

```

At [https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/action/JmsReqReplyAction.scala#L83](https://github.com/gatling/gatling/blob/master/gatling-jms/src/main/scala/io/gatling/jms/action/JmsReqReplyAction.scala#L83) the join() never returns for some reason.

I am a bit puzzled.

---

<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:** [June 5, 2015, 2:12pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/5 "2015-06-05T14:12:07Z")

</div>

I introduced a timeout on the join, but no idea what the root cause might be.  
[https://github.com/gatling/gatling/issues/2745](https://github.com/gatling/gatling/issues/2745)

---

<div class="post-metadata">

**Author:** ![Stephan\_Oudmaijer](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephan\_Oudmaijer](https://community.gatling.io/u/Stephan_Oudmaijer)\
**Post date:** [June 5, 2015, 2:16pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/6 "2015-06-05T14:16:18Z")

</div>

It looks like it is still in the waiting loop for

```auto
val m = replyConsumer.receive(receiveTimeout)

```

when I define the receiveTimeout on the jmsConfig it actually stop with the message

16:14:45.308 [ERROR] i.g.j.JmsReqReplyAction - Blocking receive returned null. Possibly the consumer was closed.

---

<div class="post-metadata">

**Author:** ![Stephan\_Oudmaijer](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephan\_Oudmaijer](https://community.gatling.io/u/Stephan_Oudmaijer)\
**Post date:** [June 5, 2015, 2:17pm UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/7 "2015-06-05T14:17:36Z")

</div>

I will give it a try! Thanks!

---

<div class="post-metadata">

**Author:** ![dgldns](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dgldns](https://community.gatling.io/u/dgldns)\
**Post date:** [October 23, 2017, 10:56am UTC](https://community.gatling.io/t/jms-simulation-does-not-shutdown-after-successful-run/2338/8 "2017-10-23T10:56:37Z")

</div>

Hi Stephen,

Did you get this working?

I see exactly same error, but not sure how to get this working.

“[ERROR] i.g.j.a.JmsReqReplyActor - Blocking receive returned null. Possibly the consumer was closed.”

Please can you advise

Thanks
