Minimal reproduction of the issue of tapir-netty server not shutting down gracefully while there are in-flight requests.
Result:
[Server] started.
[Client] Sending request.
[Server] received the request.
[Client] Stopping server.
sttp.client3.SttpClientException$ConnectException: Exception when sending request: GET http://localhost:8080/hello
at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException(SttpClientExceptionExtensions.scala:13)
at sttp.client3.SttpClientExceptionExtensions.defaultExceptionToSttpClientException$(SttpClientExceptionExtensions.scala:11)
at sttp.client3.SttpClientException$.defaultExceptionToSttpClientException(SttpClientException.scala:24)
at sttp.client3.HttpClientAsyncBackend.$anonfun$adjustExceptions$1(HttpClientAsyncBackend.scala:147)
at sttp.client3.SttpClientException$$anonfun$adjustExceptions$1.applyOrElse(SttpClientException.scala:35)
at sttp.client3.SttpClientException$$anonfun$adjustExceptions$1.applyOrElse(SttpClientException.scala:34)
at scala.concurrent.impl.Promise$Transformation.run$$$capture(Promise.scala:490)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
at java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)
at java.net.http/jdk.internal.net.http.PlainHttpConnection$ConnectEvent.handle(PlainHttpConnection.java:128)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:957)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:912)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:912)
[Client] Stopped server.
[Server] successfully processed the request.
[Application] shutdown signal received.
Expectation:
[Server] started.
[Client] Sending request.
[Server] received the request.
[Client] Stopping server.
[Server] successfully processed the request.
[Client] Response received: Response(Right(Hello World!),200,,List(content-length: 12, content-type: text/plain; charset=UTF-8),List(),RequestMetadata(GET,http://localhost:8080/hello,Vector()))
[Client] Stopped server.
[Application] shutdown signal received.
Posted this reproduction scenario to Tapir project
softwaremill/tapir#3000