Skip to content

Commit

Permalink
ConnectionClosedErrors solved?
Browse files Browse the repository at this point in the history
  • Loading branch information
joan38 committed Feb 3, 2025
1 parent 89f300b commit 15aa36f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,6 @@ class KubernetesClient[F[_]: Async: Logger](
encoder: Encoder[CustomResource[A, B]],
decoder: Decoder[CustomResource[A, B]]
) = new CustomResourcesApi[F, A, B](httpClient, config, authorization, context)

def customRequest(
request: Request[F]
): F[Request[F]] =
Request[F](
method = request.method,
uri = config.server.resolve(request.uri),
httpVersion = request.httpVersion,
headers = request.headers,
body = request.body,
attributes = request.attributes
).withOptionalAuthorization(authorization)

def customRequest(request: WSRequest): F[WSRequest] =
WSRequest(
uri = config.server.resolve(request.uri),
headers = request.headers,
method = request.method
).withOptionalAuthorization(authorization)

}

object KubernetesClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private[client] class NamespacedPodsApi[F[_]](
dataStream = sendWithRetry *> Stream.eval(signal.set(true))

output = connection.receiveStream
.through(skipConnectionClosedErrors)
// .through(skipConnectionClosedErrors)
.through(processWebSocketData)
.interruptWhen(signal)
.concurrently(dataStream)
Expand Down Expand Up @@ -239,7 +239,7 @@ private[client] class NamespacedPodsApi[F[_]](
.flatMap(request => Stream.resource(wsClient.connectHighLevel(request)))
.flatMap { connection =>
connection.receiveStream
.through(skipConnectionClosedErrors)
// .through(skipConnectionClosedErrors)
.through(processWebSocketData)
}

Expand All @@ -254,20 +254,20 @@ private[client] class NamespacedPodsApi[F[_]](
): F[(List[ExecStream], Option[ErrorOrStatus])] =
foldStream(execStream(podName, container, command, stdin, stdout, stderr, tty))

private def skipConnectionClosedErrors: Pipe[F, WSDataFrame, WSDataFrame] =
_.map(_.some)
.recover {
// Need to handle (and ignore) this exception
//
// Because of the "conflict" between the http4s WS client and
// the underlying JDK WS client (which are both high-level clients)
// an extra "Close" frame gets sent to the server, potentially
// after the TCP connection is closed, which causes this exception.
//
// This will be solved in a later version of the http4s (core or jdk).
case e: java.io.IOException if e.getMessage == "closed output" => none
}
.unNone
// private def skipConnectionClosedErrors: Pipe[F, WSDataFrame, WSDataFrame] =
// _.map(_.some)
// .recover {
// // Need to handle (and ignore) this exception
// //
// // Because of the "conflict" between the http4s WS client and
// // the underlying JDK WS client (which are both high-level clients)
// // an extra "Close" frame gets sent to the server, potentially
// // after the TCP connection is closed, which causes this exception.
// //
// // This will be solved in a later version of the http4s (core or jdk).
// case e: java.io.IOException if e.getMessage == "closed output" => none
// }
// .unNone

private def foldStream(
stdoutStream: Stream[F, Either[ExecStream, ErrorOrStatus]]
Expand Down

0 comments on commit 15aa36f

Please sign in to comment.