Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hanging on stream response errors #2599

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
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
@@ -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 =
Loading