Getting websocket exception that Websocket already present with same name

I am using the latest version of Gatling 3.x.
Everything works fine while performing a performance test for small duration.
When I am running for longer duration with decent vu, I get below exception for multiple calls.
Is it issue with application under test or my script issue?

 \[ERROR\] io.gatling.http.action.ws.WsConnect - Failed to build request ISN-WebSocket: Unable to create a new WebSocket with name gatling.http.webSocket: already exists.

What can I do to handle it?

Below is sample script:

public static ChainBuilder testSignalR() {

  // 1. Connect
  exec(ws("ISN-WebSocket").connect("wss://<WSS_HOST><API_PATH>/hubs/<SUBSCRIBE_HUB>"))
      // 2 & 3. Handshake + Subscribe — exit block on timeout/failure,
      //          but always reach the close() below
      .exec(
          exitBlockOnFail()
              .on(
                  // 2. Handshake → await {} ACK
                  exec(ws("ISN-WebSocket")
                          .sendText("{\"protocol\":\"json\",\"version\":1}" + RS)
                          .await(15)
                          .on(
                              ws.checkTextMessage("SignalR Handshake ACK")
                                  .check(regex("\\{\\}").exists().name("ISN-WebSocket Handshake ACK"))))
                      // 3. Subscribe invocation → await type-3 completion
                      .exec(
                          ws("ISN-WebSocket")
                              .sendText("{\"arguments\":[\"#{user_uid}\"],\"invocationId\":\"0\",\"target\":\"SubscribeNewDataAvailableNotification\",\"type\":1}" + RS)
                              .await(15)
                              .on(
                                  ws.checkTextMessage("SignalR Subscribe ACK")
                                      .check(regex("\"type\"\\s*:\\s*3").exists().name("ISN-WebSocket Subscribe Completion")))))))

      // 4. Close — always executed even if handshake/subscribe failed/timed out
      .exec(ws("ISN-WebSocket").close())
      .pause(2, 5);
}

I don’t think you’ve shared a sample that matches your issue.
The only place that this error message is in connect, see gatling/gatling-http/src/main/scala/io/gatling/http/action/ws/WsConnect.scala at main · gatling/gatling · GitHub.
The only way to trigger it is to have a given virtual user call connect multiple times without calling close in between.

So, I am calling the testSignalR() method inside a separate group call. The point you mentioned is absolutely valid — the exception occurs only when there are multiple connect calls without a proper close.

To handle this scenario, I have used exitBlockOnFail. This ensures that the close call is always invoked, even if there is a failure at any point in between the execution.

However, my concern is that in some cases the close call might not be completing successfully, and because of that, the subsequent connect call ends up throwing an exception.

Do we have a way to verify or validate that the close operation has completed successfully before initiating the next connect call?

I’ve checked the code and don’t see a path where we don’t remove the WebSocket on close, even in the event of a crash.

I’d need a proper reproducer.

I refered the code shared by you and I am able to resolve it by using namedWs to create connection.
Thanks a lot

Do you mean it’s intended that each virtual user opens several WebSockets?

  1. The WebSocket call is only one part of a larger flow.
  2. The entire flow runs with a pacing of 60 seconds and is executed multiple times for each vu.
  3. Also, in entire flow we have 3 different websockets.
  4. All the WebSocket connection automatically closes after 15 seconds if no messages are sent.

Due to these conditions, I am explicitly closing the WebSocket connection in each loop iteration to ensure proper connection handling and avoid unexpected disconnects.

Happy to hear if you have better solution for this situation.

Sorry, I can’t help without you providing a full reproducer I can run myself.You can try to build one using Free WebSocket Echo Server: Test Connections at echo.websocket.org | WebSocket.org

I can’t share complete code as its inside my organization policy. I will try to reproduce the same on personal system and share you the details.