Skip to content

Commit 5bfc39c

Browse files
author
r3-build
committed
Merging forward updates from release/os/4.11 to release/os/4.12 - 2024-01-30
2 parents 9b79479 + df07b7b commit 5bfc39c

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

node-api/src/main/kotlin/net/corda/nodeapi/internal/bridging/AMQPBridgeManager.kt

+28-15
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ open class AMQPBridgeManager(keyStore: CertificateStore,
201201
logInfoWithMDC("Stopping Artemis because stopping AMQP bridge")
202202
closeConsumer()
203203
consumer = null
204+
val closingSession = session
204205
eventLoop.execute {
205206
artemis(ArtemisState.STOPPING) {
206-
stopSession()
207+
stopSession(session)
208+
if(session != closingSession) {
209+
stopSession(closingSession)
210+
}
207211
session = null
208212
ArtemisState.STOPPED
209213
}
@@ -271,19 +275,28 @@ open class AMQPBridgeManager(keyStore: CertificateStore,
271275
logInfoWithMDC("Stopping Artemis because AMQP bridge disconnected")
272276
closeConsumer()
273277
consumer = null
278+
val closingSession = session
274279
eventLoop.execute {
275-
artemis(ArtemisState.STOPPING) {
276-
stopSession()
277-
session = null
278-
when (precedingState) {
279-
ArtemisState.AMQP_STOPPED ->
280-
ArtemisState.STOPPED_AMQP_START_SCHEDULED(scheduledArtemis(artemisHeartbeatPlusBackoff,
281-
TimeUnit.MILLISECONDS, ArtemisState.AMQP_STARTING) { startOutbound() })
282-
ArtemisState.AMQP_RESTARTED -> {
283-
artemis(ArtemisState.AMQP_STARTING) { startOutbound() }
284-
ArtemisState.AMQP_STARTING
280+
synchronized(artemis!!) {
281+
if (session == closingSession) {
282+
artemis(ArtemisState.STOPPING) {
283+
stopSession(session)
284+
session = null
285+
when (precedingState) {
286+
ArtemisState.AMQP_STOPPED ->
287+
ArtemisState.STOPPED_AMQP_START_SCHEDULED(scheduledArtemis(artemisHeartbeatPlusBackoff,
288+
TimeUnit.MILLISECONDS, ArtemisState.AMQP_STARTING) { startOutbound() })
289+
290+
ArtemisState.AMQP_RESTARTED -> {
291+
artemis(ArtemisState.AMQP_STARTING) { startOutbound() }
292+
ArtemisState.AMQP_STARTING
293+
}
294+
295+
else -> ArtemisState.STOPPED
296+
}
285297
}
286-
else -> ArtemisState.STOPPED
298+
} else {
299+
stopSession(closingSession)
287300
}
288301
}
289302
}
@@ -339,10 +352,10 @@ open class AMQPBridgeManager(keyStore: CertificateStore,
339352
}
340353
}
341354

342-
private fun stopSession(): Boolean {
355+
private fun stopSession(localSession: ClientSession?): Boolean {
343356
var stopped = false
344357
try {
345-
session?.apply {
358+
localSession?.apply {
346359
if (!isClosed) {
347360
stop()
348361
}
@@ -356,7 +369,7 @@ open class AMQPBridgeManager(keyStore: CertificateStore,
356369
}
357370

358371
private fun restartSession(): Boolean {
359-
if (!stopSession()) {
372+
if (!stopSession(session)) {
360373
// Session timed out stopping. The request/responses can be out of sequence on the session now, so abandon it.
361374
session = null
362375
// The consumer is also dead now too as attached to the dead session.

0 commit comments

Comments
 (0)