-
Notifications
You must be signed in to change notification settings - Fork 462
Closed
Description
Tapir version: 1.11.41
Scala version: 3.7.2
Describe the bug
I'm trying to understand the OX library, and I'm stuck on a problem. I have a simple HTTP server that accepts requests and has a long-running task. So, I immediately return the status code "Accepted" and run the long-running task on a separate thread. The error I get is:
java.lang.IllegalStateException: Forks can only be started inside a concurrency scope, or from other forks started in the scope.
How to reproduce?
//> using scala 3.7.2
//> using dep com.softwaremill.sttp.tapir::tapir-core:1.11.41
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.11.41
//> using dep ch.qos.logback:logback-classic:1.5.18
import ox.*
import sttp.model.StatusCode
import sttp.tapir.*
import sttp.tapir.server.netty.sync.NettySyncServer
import scala.concurrent.duration.DurationInt
object Main extends OxApp:
def run(args: Vector[String])(using Ox): ExitCode =
val helloWorld = endpoint.get
.in("hello")
.in(query[String]("name"))
.out(stringBody)
.out(statusCode(StatusCode.Accepted))
.handleSuccess { name =>
println("Request")
fork(longRunningTask())
println("Response")
s"Hello, $name!"
}
NettySyncServer().addEndpoint(helloWorld).startAndWait()
ExitCode.Success
private def longRunningTask(): Unit =
println("Start")
sleep(5.seconds)
println("End")Additional information
Endpoint for testing: http://localhost:8080/hello?name=xxx
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels