Skip to content

Commit 8aca1a1

Browse files
authored
Merge pull request #425 from softwaremill/pong-closed
Ignore send exceptions when replying to a ping as the WS might be closed
2 parents 9364206 + c671a31 commit 8aca1a1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ws/src/main/scala/sttp/ws/WebSocket.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ trait WebSocket[F[_]] {
5151
case close: WebSocketFrame.Close => monad.error(WebSocketClosed(Some(close)))
5252
case d: WebSocketFrame.Data[_] => monad.unit(d)
5353
case WebSocketFrame.Ping(payload) if pongOnPing =>
54-
send(WebSocketFrame.Pong(payload)).flatMap(_ => receiveDataFrame(pongOnPing))
54+
send(WebSocketFrame.Pong(payload))
55+
// https://github.com/softwaremill/sttp/issues/2236: after a Ping frame is received, the WS might have become
56+
// closed. This would cause this call to fail with an exception, while the WS was properly used. That's why
57+
// we ignore the exception here, and allow for closure (or actual I/O exception) to be discovered via the
58+
// subsequent `receive`.
59+
.handleError { case _ => monad.unit(()) }
60+
.flatMap(_ => receiveDataFrame(pongOnPing))
5561
case _ => receiveDataFrame(pongOnPing)
5662
}
5763

0 commit comments

Comments
 (0)