Error in client codegen by URL
DGolubets opened this issue · comments
I got an error in the most recent version: 2.2.1
Exception when sending request: POST
Debugging showed that the actual error was:
EOF reached
It seems to originate in the latest version of STTP. When downgraded, everything works:
dependencyOverrides += "com.softwaremill.sttp.client3" %% "zio" % "3.8.15"
You mean you downgraded the version you were depending on?
Caliban 2.1.1 itself is using sttp 3.8.15, it was upgraded to 3.8.16 only a few days ago (#1786).
I was wrong about the version actually. The error is still there..
It's a brand new project I'm starting and these are all the dependencies I have:
libraryDependencies += "dev.zio" %% "zio" % "2.0.15"
libraryDependencies += "dev.zio" %% "zio-streams" % "2.0.15"
libraryDependencies += ("io.getquill" %% "quill-jdbc-zio" % "4.6.0.1")
.exclude("com.lihaoyi", "geny_2.13")
libraryDependencies += ("org.postgresql" % "postgresql" % "42.3.1")
libraryDependencies += "com.github.ghostdogpr" %% "caliban" % "2.2.1"
libraryDependencies += "com.github.ghostdogpr" %% "caliban-zio-http" % "2.2.1"
libraryDependencies += "com.github.ghostdogpr" %% "caliban-client" % "2.2.1"
libraryDependencies ++= Seq(
"dev.zio" %% "zio-test" % "2.0.15" % Test,
"dev.zio" %% "zio-test-sbt" % "2.0.15" % Test,
"dev.zio" %% "zio-test-magnolia" % "2.0.15" % Test
)
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
enablePlugins(CalibanPlugin)
Compile / caliban / calibanSettings += calibanSetting(
url("http://my-service/api/graphql")
)(cs => cs.packageName("urbanmarkets.generated.image_service").clientName("GQL"))
Since it's hard to debug what happens in the plugin, could you try directly running SchemaLoader.fromIntrospection(yourUrl, None).load
and see what happens? Like where it fails exactly.
Here is the output from running SchemaLoader:
[error] (Compile / run) Exception in thread "zio-fiber-4" sttp.client3.SttpClientException$ReadException: Exception when sending request: POST http://my-service/api/graphql
[error] at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException(SttpClientExceptionExtensions.scala:25)
[error] at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException$(SttpClientExceptionExtensions.scala:9)
[error] at sttp.client3.SttpClientException$.defaultExceptionToSttpClientException(SttpClientException.scala:24)
[error] at sttp.client3.HttpClientAsyncBackend.adjustExceptions$$anonfun$1(HttpClientAsyncBackend.scala:147)
[error] at sttp.client3.SttpClientException$$anon$1.applyOrElse(SttpClientException.scala:35)
[error] at sttp.client3.SttpClientException$$anon$1.applyOrElse(SttpClientException.scala:34)
[error] at zio.ZIO.tryRescue$1$$anonfun$1(ZIO.scala:359)
[error] at scala.util.Either.fold(Either.scala:190)
[error] at zio.ZIO.tryRescue$1(ZIO.scala:359)
[error] at zio.ZIO.catchSome$$anonfun$1(ZIO.scala:361)
[error] at sttp.client3.impl.zio.RIOMonadAsyncError.error(RIOMonadAsyncError.scala:24)
[error] at sttp.client3.impl.zio.RIOMonadAsyncError.flatMap(RIOMonadAsyncError.scala:12)
[error] at caliban.tools.IntrospectionClient.sendRequest(IntrospectionClient.scala:30)
[error] at caliban.tools.IntrospectionClient.introspect(IntrospectionClient.scala:27)
[error] at caliban.tools.SchemaLoader.FromIntrospection.load(SchemaLoader.scala:33)
[error] at urbanmarkets.timeslices.images.Program2.run(Program2.scala:21)
[error] Suppressed: java.io.EOFException: EOF reached while reading
[error] at java.net.http/jdk.internal.net.http.Http2Connection$Http2TubeSubscriber.onComplete(Http2Connection.java:1371)
[error] at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:640)
[error] at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:845)
[error] at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181)
[error] at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230)
[error] at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:303)
[error] at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:256)
[error] at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:774)
[error] at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:957)
[error] at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253)
[error] at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:979)
[error] at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:934)
[error] at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
[error] at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:934)
Hmm that doesn't seem to be an error related to Caliban, it's java http client directly that is unable to call that URL.
You are right, that's the underlying HTTP client. It looks like it's using HTTP 2 by default.
Indeed when I do curl --http2
to that service I get:
curl: (92) HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
This works:
IntrospectionClient
.introspect("http://my-service/api/graphql", None)
.provideLayer(AsyncHttpClientZioBackend.layer()) # notice I've replaced HttpClientZioBackend here with AsyncHttpClientZioBackend
.flatMap { schema =>
Console.printLine(schema)
}
I still think this has to be fixed in Caliban, because there is no way to change the backend in the codegen plugin. Maybe you could add an option there?
According to docs on java.net client that is used by this sttp backend: Requests sent to servers that do not yet support HTTP/2 will automatically be downgraded to HTTP/1.1.
. I suspect the server is doing something weird. Is it a public URL?
No, it's our internal address.
I've just investigated a bit more with our admin and we think the culprit is HAProxy, which we use for our VPN.
According to this: https://andreaskaris.github.io/blog/networking/haproxy-and-h2c/ it doesn't support the connection upgrade.
Closing as I don't think we need to support this case.