diff --git a/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt b/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt index fe94236791..fa57922e1e 100644 --- a/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt +++ b/node/src/main/kotlin/net/corda/node/services/network/PersistentNetworkMapCache.kt @@ -248,21 +248,22 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal) private fun updateInfoDB(nodeInfo: NodeInfo) { // TODO Temporary workaround to force isolated transaction (otherwise it causes race conditions when processing // network map registration on network map node) - val session = serviceHub.database.entityManagerFactory.withOptions().connection(serviceHub.database.dataSource.connection - .apply { - transactionIsolation = 1 - }).openSession() - - val tx = session.beginTransaction() - // TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo? - val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey) - val nodeInfoEntry = generateMappedObject(nodeInfo) - if (info.isNotEmpty()) { - nodeInfoEntry.id = info[0].id + serviceHub.database.dataSource.connection.use { + val session = serviceHub.database.entityManagerFactory.withOptions().connection(it.apply { + transactionIsolation = 1 + }).openSession() + session.use { + val tx = session.beginTransaction() + // TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo? + val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey) + val nodeInfoEntry = generateMappedObject(nodeInfo) + if (info.isNotEmpty()) { + nodeInfoEntry.id = info[0].id + } + session.merge(nodeInfoEntry) + tx.commit() + } } - session.merge(nodeInfoEntry) - tx.commit() - session.close() } private fun removeInfoDB(nodeInfo: NodeInfo) {