Skip to content

Log if GRPC server/channel exceeds shutdown timeout #33

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

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ Current status: 6/79 tests pass

Known issues:

* `fs2-grpc` server implementation doesn't support setting response headers (which is required by the tests)
* `google.protobuf.Any` serialization doesn't follow Connect-RPC spec
* `fs2-grpc` server implementation doesn't support setting response headers (which is required by the tests): [#31](https://github.com/igor-vovk/connect-rpc-scala/issues/31)
* `google.protobuf.Any` serialization doesn't follow Connect-RPC spec: [#32](https://github.com/igor-vovk/connect-rpc-scala/issues/32)

## Future improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.ivovk.connect_rpc_scala

import cats.Endo
import cats.effect.{Resource, Sync}
import cats.implicits.*
import io.grpc.*
import io.grpc.inprocess.{InProcessChannelBuilder, InProcessServerBuilder}
import org.slf4j.{Logger, LoggerFactory}

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
Expand All @@ -13,6 +13,8 @@ import scala.util.chaining.*

object InProcessChannelBridge {

private val logger: Logger = LoggerFactory.getLogger(getClass)

def create[F[_] : Sync](
services: Seq[ServerServiceDefinition],
serverBuilderConfigurator: Endo[ServerBuilder[?]] = identity,
Expand Down Expand Up @@ -40,8 +42,13 @@ object InProcessChannelBridge {
.build()
.start()
}
val release = (s: Server) =>
Sync[F].delay(s.shutdown().awaitTermination(waitForShutdown.toMillis, TimeUnit.MILLISECONDS)).void
val release = (s: Server) => Sync[F].delay {
val res = s.shutdown().awaitTermination(waitForShutdown.toMillis, TimeUnit.MILLISECONDS)

if (!res) {
logger.warn(s"GRPC server did not shut down in $waitForShutdown")
}
}

Resource.make(acquire)(release)
}
Expand All @@ -57,8 +64,13 @@ object InProcessChannelBridge {
.pipe(channelBuilderConfigurator)
.build()
}
val release = (c: ManagedChannel) =>
Sync[F].delay(c.shutdown().awaitTermination(waitForShutdown.toMillis, TimeUnit.MILLISECONDS)).void
val release = (c: ManagedChannel) => Sync[F].delay {
val res = c.shutdown().awaitTermination(waitForShutdown.toMillis, TimeUnit.MILLISECONDS)

if (!res) {
logger.warn(s"GRPC channel did not shut down in $waitForShutdown")
}
}

Resource.make(acquire)(release)
}
Expand Down