fixed shutdown issue
All checks were successful
CI / build (push) Successful in 16m6s

This commit is contained in:
2025-03-03 22:02:00 +08:00
parent 4aced1c717
commit 17215b401a
2 changed files with 23 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ import io.netty.channel.socket.SocketChannel
import net.woggioni.rbcs.api.CacheHandlerFactory import net.woggioni.rbcs.api.CacheHandlerFactory
import net.woggioni.rbcs.api.Configuration import net.woggioni.rbcs.api.Configuration
import net.woggioni.rbcs.common.HostAndPort import net.woggioni.rbcs.common.HostAndPort
import net.woggioni.rbcs.common.createLogger
import net.woggioni.rbcs.server.memcache.client.MemcacheClient import net.woggioni.rbcs.server.memcache.client.MemcacheClient
import java.time.Duration import java.time.Duration
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
@@ -25,6 +26,10 @@ data class MemcacheCacheConfiguration(
val chunkSize: Int val chunkSize: Int
) : Configuration.Cache { ) : Configuration.Cache {
companion object {
private val log = createLogger<MemcacheCacheConfiguration>()
}
enum class CompressionMode { enum class CompressionMode {
/** /**
* Deflate mode * Deflate mode
@@ -69,6 +74,9 @@ data class MemcacheCacheConfiguration(
val pools = connectionPoolMap.values.toList() val pools = connectionPoolMap.values.toList()
val npools = pools.size val npools = pools.size
val finished = AtomicInteger(0) val finished = AtomicInteger(0)
if (pools.isEmpty()) {
complete(null)
} else {
pools.forEach { pool -> pools.forEach { pool ->
pool.closeAsync().addListener { pool.closeAsync().addListener {
if (!it.isSuccess) { if (!it.isSuccess) {
@@ -84,6 +92,7 @@ data class MemcacheCacheConfiguration(
} }
} }
} }
}
} }

View File

@@ -368,13 +368,14 @@ class RemoteBuildCacheServer(private val cfg: Configuration) {
private val bossGroup: EventExecutorGroup, private val bossGroup: EventExecutorGroup,
private val executorGroups: Iterable<EventExecutorGroup>, private val executorGroups: Iterable<EventExecutorGroup>,
private val serverInitializer: AsyncCloseable, private val serverInitializer: AsyncCloseable,
) : Future<Void> by from(closeFuture, executorGroups, serverInitializer) { ) : Future<Void> by from(closeFuture, bossGroup, executorGroups, serverInitializer) {
companion object { companion object {
private val log = createLogger<ServerHandle>() private val log = createLogger<ServerHandle>()
private fun from( private fun from(
closeFuture: ChannelFuture, closeFuture: ChannelFuture,
bossGroup: EventExecutorGroup,
executorGroups: Iterable<EventExecutorGroup>, executorGroups: Iterable<EventExecutorGroup>,
serverInitializer: AsyncCloseable serverInitializer: AsyncCloseable
): CompletableFuture<Void> { ): CompletableFuture<Void> {
@@ -382,22 +383,15 @@ class RemoteBuildCacheServer(private val cfg: Configuration) {
closeFuture.addListener { closeFuture.addListener {
val errors = mutableListOf<Throwable>() val errors = mutableListOf<Throwable>()
val deadline = Instant.now().plusSeconds(20) val deadline = Instant.now().plusSeconds(20)
try {
serverInitializer.close()
} catch (ex: Throwable) {
log.error(ex.message, ex)
errors.addLast(ex)
}
serverInitializer.asyncClose().whenComplete { _, ex -> serverInitializer.asyncClose().whenCompleteAsync { _, ex ->
if(ex != null) { if(ex != null) {
log.error(ex.message, ex) log.error(ex.message, ex)
errors.addLast(ex) errors.addLast(ex)
} }
executorGroups.map { executorGroups.forEach(EventExecutorGroup::shutdownGracefully)
it.shutdownGracefully() bossGroup.terminationFuture().sync()
}
for (executorGroup in executorGroups) { for (executorGroup in executorGroups) {
val future = executorGroup.terminationFuture() val future = executorGroup.terminationFuture()