HTTP: WebSocket doesn't properly recover after reconnecting
See original GitHub issueEnvironment:
- Gatling version: 3.6.1 / 3.7.0-M1
- Gatling Gradle plugin version: 3.7.0-M1
Issue
My observation about .onConnected()
, .wsMaxReconnects()
method. When I forced on server side to close connection (eg. 1003 code) during foreach loop by sending binary message, then Gatling reconnects and calls again .onConnected
method which is correct behaviour, but on second attempt it freezes after sending & receiving Config Frame … Please see below code & logs.
Did I discover a BUG?
Another thing, I set wsMaxReconnects
to 0
, the Gatling still reconnects, I think it shouldn’t reconnect.
Code
import io.gatling.core.Predef.{exec, _}
import io.gatling.http.Predef._
import java.nio.file.{Files, Paths}
import scala.concurrent.duration.DurationInt
class BasicSimulationCall extends Simulation {
val byteArray = Files.readAllBytes(Paths.get("<PATH_TO_SOME_FILE_EG_IMAGE>"))
val httpProtocol = http
.baseUrl("http://localhost:8080/v1/")
.wsBaseUrl("ws://localhost:8080/v1/")
.wsReconnect
.wsMaxReconnects(0)
.disableWarmUp
val chunkSize: Int = 8000
def sendToWS = {
exec(
ws("WS Connect")
.connect("123/521beea1-2cd1-4fa3-b087-e862a39e1000/1")
.await(300.millis)(
ws.checkTextMessage("checkConnection")
.check(jsonPath("$.message").is("Connection - OK"))
)
.onConnected(
exec(
ws("Send Config Frame")
.sendText(s"{'ChannelId': 'ch-123', 'OperatorId': 'JohnDoe'}")
.await(500.second)(
ws.checkTextMessage("checkCfgFrame")
.check(jsonPath("$.message").is("Config Frame - OK"))
)
).pause(500.millis)
)
)
.pause(1)
.foreach(byteArray.grouped(chunkSize).toSeq, "packet") {
exec(
ws("Send bytes").sendBytes("${packet}")
//Here I don't wait for any response message - from the server side I don't want to send message like ACK
).pause(250.millis)
}
.pause(100.millis)
.exec(ws("Close WS").close)
}
val scn = scenario("Web Socket test")
.exec(sendToWS)
setUp(
scn.inject(rampUsers(1).during(1)).protocols(httpProtocol)
)
}
Output logs
Simulation BasicSimulationCall started...
13:14:18.222 [DEBUG] i.g.h.a.w.WsConnect - Opening websocket 'gatling.http.webSocket': Scenario 'Web Socket test', UserId #1
13:14:18.229 [DEBUG] i.g.h.a.w.f.WsConnectingState$ - Connecting to ws://localhost:8080/v1/123/521beea1-2cd1-4fa3-b087-e862a39e1000/1
13:14:18.912 [DEBUG] i.g.h.a.w.WsListener - Received response to WebSocket CONNECT: 101 Switching Protocols DefaultHttpHeaders[upgrade: websocket, connection: upgrade, sec-websocket-accept: 18+bn2TEKXYnmcNTb32TbRkUCM4=, content-length: 0]
13:14:18.915 [DEBUG] i.g.h.a.w.f.WsConnectingState - Connected, performing checks, setting callback to perform next action after performing onConnected action
13:14:18.916 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1536879719 scheduled
13:14:18.932 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Received matching message {"message": "Connection - OK", "sessionId": "tWxsOCtdQAlbqIh5TVpUsg=="}
13:14:18.932 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1536879719 cancelled
13:14:18.968 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check success
13:14:18.968 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Check sequences completed successfully
13:14:18.971 [DEBUG] i.g.h.a.w.WsSendTextFrame - Sending text frame {'ChannelId': 'ch-123', 'OperatorId': 'JohnDoe'} with WebSocket '<function1>': Scenario 'Web Socket test', UserId #1
13:14:18.971 [DEBUG] i.g.h.a.w.f.WsIdleState - Send text frame Send Config Frame {'ChannelId': 'ch-123', 'OperatorId': 'JohnDoe'}
13:14:18.972 [DEBUG] i.g.h.a.w.f.WsIdleState - Trigger check after sending text frame
13:14:18.972 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 87394968 scheduled
13:14:20.815 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Received matching message {"message": "Config Frame - OK", "sessionId": "tWxsOCtdQAlbqIh5TVpUsg=="}
13:14:20.815 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 87394968 cancelled
13:14:20.816 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check success
13:14:20.816 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Check sequences completed successfully
13:14:22.328 [DEBUG] i.g.h.a.w.WsSendBinaryFrame - Sending binary frame of 8000 bytes with WebSocket '<function1>': Scenario 'Web Socket test', UserId #1
13:14:22.329 [DEBUG] i.g.h.a.w.f.WsIdleState - Send binary frame Send bytes length=8000
13:14:22.348 [DEBUG] i.g.h.a.w.f.WsIdleState - WebSocket was forcefully closed (1003:Unsupported Data) by the server while in Idle state
13:14:22.586 [DEBUG] i.g.h.a.w.WsSendBinaryFrame - Sending binary frame of 8000 bytes with WebSocket '<function1>': Scenario 'Web Socket test', UserId #1
13:14:22.587 [DEBUG] i.g.h.a.w.f.WsCrashedState - Client issued message but WebSocket was already closed
13:14:22.587 [DEBUG] i.g.h.a.w.f.WsConnectingState$ - Connecting to ws://localhost:8080/v1/123/521beea1-2cd1-4fa3-b087-e862a39e1000/1
13:14:22.600 [DEBUG] i.g.h.a.w.WsListener - Received response to WebSocket CONNECT: 101 Switching Protocols DefaultHttpHeaders[upgrade: websocket, connection: upgrade, sec-websocket-accept: oJcUzHzFAHK8YiPQn/C6PhUJvME=, content-length: 0]
13:14:22.601 [DEBUG] i.g.h.a.w.f.WsConnectingState - Connected, performing checks, setting callback to send pending message after performing onConnected action
13:14:22.602 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1764290324 scheduled
13:14:22.602 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Received matching message {"message": "Connection - OK", "sessionId": "yX4D6JCTC/r7VNBWuLQckw=="}
13:14:22.602 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1764290324 cancelled
13:14:22.602 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check success
13:14:22.602 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Check sequences completed successfully
13:14:22.603 [DEBUG] i.g.h.a.w.WsSendTextFrame - Sending text frame {'ChannelId': 'ch-123', 'OperatorId': 'JohnDoe'} with WebSocket '<function1>': Scenario 'Web Socket test', UserId #1
13:14:22.603 [DEBUG] i.g.h.a.w.f.WsIdleState - Send text frame Send Config Frame {'ChannelId': 'ch-123', 'OperatorId': 'JohnDoe'}
13:14:22.603 [DEBUG] i.g.h.a.w.f.WsIdleState - Trigger check after sending text frame
13:14:22.603 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 521765391 scheduled
13:14:23.178 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Received matching message {"message": "Config Frame - OK", "sessionId": "yX4D6JCTC/r7VNBWuLQckw=="}
13:14:23.178 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 521765391 cancelled
13:14:23.178 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check success
13:14:23.179 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Check sequences completed successfully
================================================================================
2021-11-25 13:14:23 5s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=9 KO=0 )
> WS Connect (OK=2 KO=0 )
> checkConnection (OK=2 KO=0 )
> Send Config Frame (OK=2 KO=0 )
> checkCfgFrame (OK=2 KO=0 )
> Send bytes (OK=1 KO=0 )
---- Web Socket test -----------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-11-25 13:14:28 10s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=9 KO=0 )
> WS Connect (OK=2 KO=0 )
> checkConnection (OK=2 KO=0 )
> Send Config Frame (OK=2 KO=0 )
> checkCfgFrame (OK=2 KO=0 )
> Send bytes (OK=1 KO=0 )
---- Web Socket test -----------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-11-25 13:14:33 15s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=9 KO=0 )
> WS Connect (OK=2 KO=0 )
> checkConnection (OK=2 KO=0 )
> Send Config Frame (OK=2 KO=0 )
> checkCfgFrame (OK=2 KO=0 )
> Send bytes (OK=1 KO=0 )
---- Web Socket test -----------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-11-25 13:14:38 20s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=9 KO=0 )
> WS Connect (OK=2 KO=0 )
> checkConnection (OK=2 KO=0 )
> Send Config Frame (OK=2 KO=0 )
> checkCfgFrame (OK=2 KO=0 )
> Send bytes (OK=1 KO=0 )
---- Web Socket test -----------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top Results From Across the Web
How to reconnect to websocket after close connection [duplicate]
Just make a new WebSocket again. The reason a reconnect doesn't exist is because it would probably be just like creating a new...
Read more >Best way to reconnect? · Issue #81 · jmesnil/stomp-websocket
I was wondering what should be the best way to reconnect after losing connection. I'm facing a case where an HTML5 app lose...
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 version of...
Read more >Auto WebSocket Reconnection with RxJS (with Example)
In this RxJS tutorial article, we will focus on restoring the websocket connection when using RxJS library.
Read more >Create reliable Websocket clients - Microsoft Learn
Reconnection. Websocket connections relay on TCP, so if the connection doesn't drop, all messages should be lossless and in order.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fix works like a charm 😄 . Thanks.
Looks like a gradle download issue. It’s definitely released (so is the gradle plugin).
The binaries are online, but the indexes on search.maven.org take some time to get updated. You should check the files directly (Browse button): https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts/3.7.2/