Skip to content

Commit

Permalink
Fix hanging on stream response errors (zio#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Jan 7, 2024
1 parent 7458b6f commit 51bfe0f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ private[zio] final case class ServerInboundHandler(
}
None
}
}.flatMap(_.getOrElse(ZIO.unit)).catchSomeCause { case cause =>
ZIO.attempt(
attemptFastWrite(ctx, withDefaultErrorResponse(cause.squash)),
)
}
}.foldCauseZIO(
cause => ZIO.attempt(attemptFastWrite(ctx, withDefaultErrorResponse(cause.squash))),
{
case None => ZIO.unit
case Some(task) => task.orElse(ZIO.attempt(ctx.close()))
},
)
}

pgm.provideEnvironment(env)
Expand Down
26 changes: 26 additions & 0 deletions zio-http/src/test/scala/zio/http/ServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,32 @@ object ServerSpec extends HttpRunnableSpec {
.run()
assertZIO(res)(equalTo("foo\nbar"))
} @@ TestAspect.os(os => !os.isWindows),
test("streaming failure - known content type") {
val res =
Handler
.fromStream(ZStream.fromZIO(ZIO.attempt(throw new Exception("boom"))), 42)
.sandbox
.toHttpApp
.deploy
.body
.mapZIO(_.asString)
.run()
.exit
assertZIO(res)(failsWithA[java.io.IOException])
} @@ TestAspect.timeout(10.seconds),
test("streaming failure - unknown content type") {
val res =
Handler
.fromStreamChunked(ZStream.fromZIO(ZIO.attempt(throw new Exception("boom"))))
.sandbox
.toHttpApp
.deploy
.body
.mapZIO(_.asString)
.run()
.exit
assertZIO(res)(failsWithA[java.io.IOException])
} @@ TestAspect.timeout(10.seconds),
suite("html")(
test("body") {
val res =
Expand Down

0 comments on commit 51bfe0f

Please sign in to comment.