mirror of
https://github.com/corda/corda.git
synced 2024-12-21 22:07:55 +00:00
[CORDA-1455]: Error in process-id deletion process allows multiple instances of same node to be run (fix). (#3118)
This commit is contained in:
parent
ecc0560ebc
commit
3a218b228d
@ -226,7 +226,6 @@ open class NodeStartup(val args: Array<String>) {
|
|||||||
// twice with the same directory: that's a user error and we should bail out.
|
// twice with the same directory: that's a user error and we should bail out.
|
||||||
val pidFile = (baseDirectory / "process-id").toFile()
|
val pidFile = (baseDirectory / "process-id").toFile()
|
||||||
pidFile.createNewFile()
|
pidFile.createNewFile()
|
||||||
pidFile.deleteOnExit()
|
|
||||||
val pidFileRw = RandomAccessFile(pidFile, "rw")
|
val pidFileRw = RandomAccessFile(pidFile, "rw")
|
||||||
val pidFileLock = pidFileRw.channel.tryLock()
|
val pidFileLock = pidFileRw.channel.tryLock()
|
||||||
if (pidFileLock == null) {
|
if (pidFileLock == null) {
|
||||||
@ -234,6 +233,7 @@ open class NodeStartup(val args: Array<String>) {
|
|||||||
println("Shut that other node down and try again. It may have process ID ${pidFile.readText()}")
|
println("Shut that other node down and try again. It may have process ID ${pidFile.readText()}")
|
||||||
System.exit(1)
|
System.exit(1)
|
||||||
}
|
}
|
||||||
|
pidFile.deleteOnExit()
|
||||||
// Avoid the lock being garbage collected. We don't really need to release it as the OS will do so for us
|
// Avoid the lock being garbage collected. We don't really need to release it as the OS will do so for us
|
||||||
// when our process shuts down, but we try in stop() anyway just to be nice.
|
// when our process shuts down, but we try in stop() anyway just to be nice.
|
||||||
addShutdownHook {
|
addShutdownHook {
|
||||||
|
Loading…
Reference in New Issue
Block a user