zio / zio-lambda

AWS Lambda Runtime built with ZIO
https://zio.dev/zio-lambda
Apache License 2.0
38 stars 14 forks source link

"java.io.IOException: too many bytes written" when application fail with error message that contains non-ASCII character #193

Closed heaven-born closed 1 year ago

heaven-born commented 1 year ago

Can be reproduced something like this:

object EntryPoint extends ZLambda[KinesisEvent, String] { self =>

  val badText: Char = '\u03A9'

  override def apply(event: KinesisEvent, context: Context): Task[String] =
    for {
            _ <- ZIO.fail(RuntimeException(s"good_test_${badText}_good_text"))
    } yield "success"

}

The fix should be somewhere in zio.lambda.internal.RuntimeApiLive#sendInvocationError method I guess. I assume that adding Content-Length header should fix this issue.

Stack trace:

timestamp=2023-04-10T20:49:51.426360090Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.io.IOException: too many bytes written
    at java.base/sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3804)
    at java.base/sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3795)
    at zio.lambda.internal.RuntimeApiLive.postRequest$$anonfun$2(RuntimeApiLive.scala:88)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at zio.ZIOCompanionVersionSpecific.attempt$$anonfun$1(ZIOCompanionVersionSpecific.scala:103)
    at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3804)
    at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3795)
    at zio.lambda.internal.RuntimeApiLive.postRequest$$anonfun$2(RuntimeApiLive.scala:88)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at zio.ZIOCompanionVersionSpecific.attempt$$anonfun$1(ZIOCompanionVersionSpecific.scala:103)
    at zio.lambda.internal.RuntimeApiLive.postRequest(RuntimeApiLive.scala:90)
    at zio.lambda.internal.LoopProcessor.Live.loop(LoopProcessor.scala:32)
    at zio.lambda.ZLambda.run(ZLambda.scala:22)"