Skip to content
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

core: fix unrecoverable freezes of rabbit's consumer #10594

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion core/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ opentelemetry-instrumentation-annotations = { module = 'io.opentelemetry.instrum

kaml = { module = 'com.charleskorn.kaml:kaml', version = '0.66.0' } # Apache 2.0

amqp-client = { module = 'com.rabbitmq:amqp-client', version = '5.23.0' }
amqp-client = { module = 'com.rabbitmq:amqp-client', version = '5.24.0' }

[plugins]
# kotlin
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/fr/sncf/osrd/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public static void main(String[] args) {
}

// run the user command
var statusCode = commands.get(commandName).run();
var statusCode = 1;
try {
statusCode = commands.get(commandName).run();
} catch (Exception e) {
e.printStackTrace(System.err);
}
System.exit(statusCode);
}
}
26 changes: 22 additions & 4 deletions core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package fr.sncf.osrd.cli
import com.beust.jcommander.Parameter
import com.beust.jcommander.Parameters
import com.rabbitmq.client.*
import fr.sncf.osrd.api.*
import fr.sncf.osrd.api.ElectricalProfileSetManager
import fr.sncf.osrd.api.InfraLoadEndpoint
import fr.sncf.osrd.api.InfraManager
import fr.sncf.osrd.api.VersionEndpoint
import fr.sncf.osrd.api.api_v2.conflicts.ConflictDetectionEndpointV2
import fr.sncf.osrd.api.api_v2.path_properties.PathPropEndpoint
import fr.sncf.osrd.api.api_v2.pathfinding.PathfindingBlocksEndpointV2
Expand All @@ -20,6 +23,7 @@ import java.io.InputStream
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import kotlin.system.exitProcess
import okhttp3.OkHttpClient
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -289,6 +293,17 @@ class WorkerCommand : CliCommand {
executionTimeMS / 1_000.0
)
}

val terminatorCallback =
fun(message: Delivery) {
try {
callback(message)
} catch (t: Throwable) {
t.printStackTrace(System.err)
exitProcess(1)
}
}

channel.basicConsume(
WORKER_REQUESTS_QUEUE,
false,
Expand All @@ -298,12 +313,15 @@ class WorkerCommand : CliCommand {
// We directly process the message with no dispatch if there's too many
// locally queued tasks. Prevents the worker from consuming all the rabbitmq
// at once, which would mess with the stats and automatic scaling.
callback(message)
terminatorCallback(message)
} else {
executor.execute { callback(message) }
executor.execute { terminatorCallback(message) }
}
},
{ _ -> logger.error("consumer cancelled") },
{ _ ->
logger.error("consumer cancelled")
exitProcess(0)
woshilapin marked this conversation as resolved.
Show resolved Hide resolved
},
{ consumerTag, e ->
logger.info("consume shutdown: {}, {}", consumerTag, e.toString())
}
Expand Down
Loading