Skip to content
Draft
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
11 changes: 6 additions & 5 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{.push raises: [].}

import
std/[os, random, terminal, times, exitprocs],
std/[os, random, terminal, times, exitprocs, atomics],
chronos, chronicles,
metrics, metrics/chronos_httpserver,
stew/[byteutils, io2],
Expand Down Expand Up @@ -2193,9 +2193,10 @@ proc run(node: BeaconNode) {.raises: [CatchableError].} =

var gPidFile: string
proc createPidFile(filename: string) {.raises: [IOError].} =
writeFile filename, $os.getCurrentProcessId()
gPidFile = filename
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
if shouldCreatePidFile.load():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this compareandswap(true)? this way, the variable doesn't have to be public and it's guaranteed to run once only

also, this should be moved to nimbus_binary_common if it's going to be shared between binaries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be public, otherwise a different thread can not read/write.

The purpose of this change is to avoid the the error triggered by addExitProc on a threaded environment, when it tries to delete something that does not exist anymore.

Agree on moving this to nimbus_binary_common

writeFile filename, $os.getCurrentProcessId()
gPidFile = filename
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)

proc initializeNetworking(node: BeaconNode) {.async.} =
node.installMessageValidators()
Expand Down Expand Up @@ -2560,7 +2561,7 @@ proc doSlashingInterchange(conf: BeaconNodeConf) {.raises: [CatchableError].} =
of SlashProtCmd.`import`:
conf.doSlashingImport()

proc handleStartUpCmd(config: var BeaconNodeConf) {.raises: [CatchableError].} =
proc handleStartUpCmd*(config: var BeaconNodeConf) {.raises: [CatchableError].} =
# Single RNG instance for the application - will be seeded on construction
# and avoid using system resources (such as urandom) after that
let rng = HmacDrbgContext.new()
Expand Down
6 changes: 5 additions & 1 deletion beacon_chain/nimbus_binary_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import
# Standard library
std/[os, tables, strutils, terminal, typetraits],
std/[os, atomics, tables, strutils, terminal, typetraits],

# Nimble packages
chronos, confutils, presto, toml_serialization, metrics,
Expand Down Expand Up @@ -40,6 +40,10 @@ type
SlotStartProc*[T] = proc(node: T, wallTime: BeaconTime,
lastSlot: Slot): Future[bool] {.gcsafe, raises: [].}

# controls if beacon node db file lock should be created (default: true)
var shouldCreatePidFile*: Atomic[bool]
shouldCreatePidFile.store(true)

proc updateLogLevel*(logLevel: string) {.raises: [ValueError].} =
# Updates log levels (without clearing old ones)
let directives = logLevel.split(";")
Expand Down
Loading