question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP: Websocket doen't handle correctly server closing connection

See original GitHub issue

The context :

  • a client establish a websocket connection to a server
  • the client sends bytes (multiple times) and waits for server response data
  • the server returns response data and close the websocket connection right after

When the connection is closed, I get this error:

i.g.h.a.w.f.WsActor - unhandled event WebSocketCrashed(io.gatling.http.client.impl.HttpAppHandler$1: Premature close,...) in state Crashed

If the server returns only data, and the client close the websocket connection, its working fine.

I tried with Gatling 3.0.2-SNAPSHOT (which contains this fix https://github.com/gatling/gatling/issues/3630)

Sample scenario:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

import scala.concurrent.duration._

class ServerCloseSimulation extends Simulation {

  private val bytes: Array[Byte] = ???

  private val httpProtocol = http.wsBaseUrl("ws://localhost:9000")

  private val scn = scenario("ServerCloseSimulation")
    .exec(ws("Connect").connect("/"))
    .foreach(bytes.grouped(2048).toSeq, "packet") {
      exec(ws("Send bytes").sendBytes("${packet}")).pause(60.millis)
    }
    .pause(10.seconds) // fails here
    .exec(ws("Close").close)

  setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
slandellecommented, Dec 17, 2018

Here’s the simulation I ran against your sample:

class ServerCloseSimulation extends Simulation {

  private val httpProtocol = http.wsBaseUrl("ws://localhost:9000").disableWarmUp

  private val scn = scenario("ServerCloseSimulation")
    .exec(ws("Connect").connect("/?close=true"))
    .repeat(5) {
      exec(ws("Send text").sendText("Hello!"))
        .pause(60 millis)
    }
    .pause(5) // fails here
    .exec(ws("Close").close)

  setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

Then, I wonder if your problem is that you’re not increasing wsMaxReconnects.

1reaction
slandellecommented, Dec 13, 2018

Cool, thanks! Travelling this week so I might only be able to have a look next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Close a WebSocket (Correctly) - Forty Years of Code
A client WebSocket that starts the closing handshake fails to transition to the Closed state when the server acknowledges the initial Close ......
Read more >
Closing WebSocket correctly (HTML5, Javascript)
It seems insane that it doesn't close the connection. The WebSocket variable is wiped out on page reload, so why would the connection...
Read more >
WebSocket.close() - Web APIs - MDN Web Docs
close () method closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED , this method does nothing....
Read more >
Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server · The server is not reachable · The client is not compatible with the...
Read more >
Websocket connection does not terminate even when client ...
For the same, I wrote the below server code and simple client (executed in Chrome browser console). It works, but when I call...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found