Skip to content

Commit

Permalink
Merge pull request #425 from softwaremill/pong-closed
Browse files Browse the repository at this point in the history
Ignore send exceptions when replying to a ping as the WS might be closed
  • Loading branch information
adamw authored Aug 5, 2024
2 parents 9364206 + c671a31 commit 8aca1a1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ws/src/main/scala/sttp/ws/WebSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ trait WebSocket[F[_]] {
case close: WebSocketFrame.Close => monad.error(WebSocketClosed(Some(close)))
case d: WebSocketFrame.Data[_] => monad.unit(d)
case WebSocketFrame.Ping(payload) if pongOnPing =>
send(WebSocketFrame.Pong(payload)).flatMap(_ => receiveDataFrame(pongOnPing))
send(WebSocketFrame.Pong(payload))
// https://github.com/softwaremill/sttp/issues/2236: after a Ping frame is received, the WS might have become
// closed. This would cause this call to fail with an exception, while the WS was properly used. That's why
// we ignore the exception here, and allow for closure (or actual I/O exception) to be discovered via the
// subsequent `receive`.
.handleError { case _ => monad.unit(()) }
.flatMap(_ => receiveDataFrame(pongOnPing))
case _ => receiveDataFrame(pongOnPing)
}

Expand Down

0 comments on commit 8aca1a1

Please sign in to comment.