mirror of
https://github.com/corda/corda.git
synced 2025-06-22 17:09:00 +00:00
node-driver: Hacky fix of startup race condition
This commit is contained in:
@ -10,7 +10,6 @@ import com.r3corda.core.node.services.ServiceType
|
|||||||
import com.r3corda.node.services.messaging.ArtemisMessagingClient
|
import com.r3corda.node.services.messaging.ArtemisMessagingClient
|
||||||
import com.r3corda.node.services.config.NodeConfigurationFromConfig
|
import com.r3corda.node.services.config.NodeConfigurationFromConfig
|
||||||
import com.r3corda.node.services.config.copy
|
import com.r3corda.node.services.config.copy
|
||||||
import com.r3corda.node.services.messaging.ArtemisMessagingComponent
|
|
||||||
import com.r3corda.node.services.network.InMemoryNetworkMapCache
|
import com.r3corda.node.services.network.InMemoryNetworkMapCache
|
||||||
import com.r3corda.node.services.network.NetworkMapService
|
import com.r3corda.node.services.network.NetworkMapService
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
@ -245,10 +244,7 @@ class DriverDSL(
|
|||||||
|
|
||||||
// Check that we shut down properly
|
// Check that we shut down properly
|
||||||
addressMustNotBeBound(messagingService.myHostPort)
|
addressMustNotBeBound(messagingService.myHostPort)
|
||||||
val nodeInfo = networkMapNodeInfo
|
addressMustNotBeBound(networkMapAddress)
|
||||||
if (nodeInfo != null) {
|
|
||||||
addressMustNotBeBound((nodeInfo.address as ArtemisMessagingComponent.Address).hostAndPort)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,7 +291,7 @@ class DriverDSL(
|
|||||||
messagingServiceStarted = true
|
messagingServiceStarted = true
|
||||||
// We fake the network map's NodeInfo with a random public key in order to retrieve the correct NodeInfo from
|
// We fake the network map's NodeInfo with a random public key in order to retrieve the correct NodeInfo from
|
||||||
// the network map service itself
|
// the network map service itself
|
||||||
val nodeInfo = NodeInfo(
|
val fakeNodeInfo = NodeInfo(
|
||||||
address = ArtemisMessagingClient.makeRecipient(networkMapAddress),
|
address = ArtemisMessagingClient.makeRecipient(networkMapAddress),
|
||||||
identity = Party(
|
identity = Party(
|
||||||
name = networkMapName,
|
name = networkMapName,
|
||||||
@ -303,7 +299,7 @@ class DriverDSL(
|
|||||||
),
|
),
|
||||||
advertisedServices = setOf(NetworkMapService.Type)
|
advertisedServices = setOf(NetworkMapService.Type)
|
||||||
)
|
)
|
||||||
networkMapCache.addMapService(messagingService, nodeInfo, true)
|
networkMapCache.addMapService(messagingService, fakeNodeInfo, true)
|
||||||
networkMapNodeInfo = poll {
|
networkMapNodeInfo = poll {
|
||||||
networkMapCache.partyNodes.forEach {
|
networkMapCache.partyNodes.forEach {
|
||||||
if (it.identity.name == networkMapName) {
|
if (it.identity.name == networkMapName) {
|
||||||
@ -356,14 +352,11 @@ class DriverDSL(
|
|||||||
builder.redirectError(Paths.get("error.$className.log").toFile())
|
builder.redirectError(Paths.get("error.$className.log").toFile())
|
||||||
builder.inheritIO()
|
builder.inheritIO()
|
||||||
val process = builder.start()
|
val process = builder.start()
|
||||||
poll {
|
addressMustBeBound(cliParams.messagingAddress)
|
||||||
try {
|
// TODO There is a race condition here. Even though the messaging address is bound it may be the case that
|
||||||
Socket(cliParams.messagingAddress.hostText, cliParams.messagingAddress.port).close()
|
// the handlers for the advertised services are not yet registered. A hacky workaround is that we wait for
|
||||||
Unit
|
// the web api address to be bound as well, as that starts after the services. Needs rethinking.
|
||||||
} catch (_exception: SocketException) {
|
addressMustBeBound(cliParams.apiAddress)
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return process
|
return process
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import com.r3corda.node.services.api.RegulatorService
|
|||||||
import com.r3corda.node.services.messaging.ArtemisMessagingComponent
|
import com.r3corda.node.services.messaging.ArtemisMessagingComponent
|
||||||
import com.r3corda.node.services.transactions.NotaryService
|
import com.r3corda.node.services.transactions.NotaryService
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.net.Socket
|
|
||||||
import java.net.SocketException
|
|
||||||
|
|
||||||
|
|
||||||
class DriverTests {
|
class DriverTests {
|
||||||
|
Reference in New Issue
Block a user