# WebSocket wsAwait hangs indefinately, if connection closed

**URL:** <https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480>\
**Category:** Gatling (Open-Source)\
**Created:** [August 20, 2015, 3:59pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480 "2015-08-20T15:59:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slavik\_Fursov](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Slavik\_Fursov](https://community.gatling.io/u/Slavik_Fursov)\
**Post date:** [August 20, 2015, 3:59pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/1 "2015-08-20T15:59:26Z")

</div>

I have following scenario:

```auto
val scn = scenario("WebSocket")
  .exec(ws("Connect WS").open(""))
  .exec(ws("Sending query")
         .sendText(session => query())
         .check(wsAwait.within(300).until(1).regex(""".*"status":"Finished".*""").saveAs("SiftOutput"))
  )
  .exec{ session =>
      session("SiftOutput").asOption[String].foreach(println)
      session
      }
  .exec(ws("Close WS").close)

```

```auto
setUp(scn.inject(atOnceUsers(5)).protocols(httpConf))

```

During execution 1st query executes successfully, but rest 4 are times out. That’s expected failure.

The problem, is that this Gatling method couldn’t process closed connection:

```auto

```

```auto
 .check(wsAwait.within(300).until(1).regex(""".*"status":"Finished".*""").saveAs("SiftOutput"))

```

So, I expect, that it would wait up to 300 seconds. And if connection is not getting closed, that’s exactly, how it works.

But, if connection get closed, then this method never finish execution, and keep running for hours.  
Here is what I see in the console after few hours:

2015-08-20 08:38:32 56467s elapsed  
---- WebSocket -----------------------------------------------------------------  
[##############------------------------------------------------------------] 20%  
waiting: 0 / active: 4 / done:1  
---- Requests ------------------------------------------------------------------

> Global (OK=12 KO=4 )  
> Connect WS (OK=5 KO=0 )  
> Sending query (OK=5 KO=0 )  
> Sending query Check (OK=1 KO=4 )  
> Close WS (OK=1 KO=0 )  
> ---- Errors --------------------------------------------------------------------  
> Websocket ‘gatling.http.webSocket’ was unexpectedly closed wit 4 (100.0%)  
> h status 1006 and message Connection was closed abnormally (th…

So, this seems like a bug in Gatling method. Or am I not understand something about the .check(wsAwait.within(300) method?

---

<div class="post-metadata">

**Author:** ![Slavik\_Fursov](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Slavik\_Fursov](https://community.gatling.io/u/Slavik_Fursov)\
**Post date:** [August 20, 2015, 4:19pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/2 "2015-08-20T16:19:48Z")

</div>

I’m using Gatling 2.1.7.

So, my main question is how to write a code (I guess that should be a .check),  
so it

1. wait for the message up to TIMEOUT
2. OR until WebSocket gets closed

1st part can be done by wsAwait.within(300), but how I do 2nd part - how I consider WebSockets getting closed?

---

<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:** [August 20, 2015, 5:21pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/3 "2015-08-20T17:21:37Z")

</div>

This is a known issue: [https://github.com/gatling/gatling/issues/2601](https://github.com/gatling/gatling/issues/2601)

---

<div class="post-metadata">

**Author:** ![Slavik\_Fursov](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Slavik\_Fursov](https://community.gatling.io/u/Slavik_Fursov)\
**Post date:** [August 20, 2015, 8:17pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/4 "2015-08-20T20:17:29Z")

</div>

_Stéphane,_

Is issue #2241 will offer alternative way to handle the above scenario:[https://github.com/gatling/gatling/issues/2241](https://github.com/gatling/gatling/issues/2241)  
?

Slavik

---

<div class="post-metadata">

**Author:** ![Samuel\_Volin](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@Samuel\_Volin](https://community.gatling.io/u/Samuel_Volin)\
**Post date:** [September 22, 2016, 4:50pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/5 "2016-09-22T16:50:00Z")

</div>

I hate to necropost a year old thread, but has there been any further work addressing this? It seems like [the problem is known](https://github.com/gatling/gatling/issues/2601#issuecomment-219567905), but is there any solution to save a simulation that gets stuck this way?

At a minimum, it would be helpful to have a means to kill a simulation and still get the results printout (sending sigint kills the simulation, but doesn’t make the results printout). Any solution or workaround would be very helpful.

---

<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:** [September 22, 2016, 4:59pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/6 "2016-09-22T16:59:41Z")

</div>

The WebSocket support will be rebooted in Gatling 3.  
WIP happens here: [https://github.com/gatling/gatling/issues/3071](https://github.com/gatling/gatling/issues/3071)

Current state should have this fixed, but it’s only available as a preview for our Support offer subscribers.  
It will only make it into the OSS branch when we’ll release Gatling 3, at least in one year from now.

---

<div class="post-metadata">

**Author:** ![esteban.masoero](https://avatars.discourse-cdn.com/v4/letter/e/0ea827/32.png) [@esteban.masoero](https://community.gatling.io/u/esteban.masoero)\
**Post date:** [June 27, 2018, 7:40pm UTC](https://community.gatling.io/t/websocket-wsawait-hangs-indefinately-if-connection-closed/2480/7 "2018-06-27T19:40:00Z")

</div>

Hi there,

Sorry to necropost (again) this more-than-year-old thread. Are there any news about this? According to [https://github.com/gatling/gatling/issues/3071](https://github.com/gatling/gatling/issues/3071) last commit was a few months ago.

Regards,

Esteban
