collectors: fix nil Logger panic in collector startup#131
Conversation
|
I'm trying to actually test this code that has been proposed. The example error in #129 was from the race condition described in "Two ways it triggers", probably hit because of so much crash looping because of "Permanent" trigger also mentioned there (which I was also getting sometimes). I think "if initLogRotator's MkdirAll fails (e.g. running under a read-only root filesystem with the default logdir $HOME/.lndmon/logs unwritable), Start() returns early and Logger is never assigned — so it stays nil for the whole process, and any collector error (startup, or a later transient deadline exceeded) panics." (also mentioned at "Two ways it triggers" in #129, the "Permanent" trigger) might actually be a bit wrong in how it actually fails (but it still is a permanent trigger). Instead, when With this fix, I'm only getting so that may hint that this fix is working (because I no longer hit the race condition), but not necessarily prove that the fix is working. |
NewChannelsCollector launched its cache-refresh goroutine at construction time, but the package-global Logger was only initialized later in PrometheusExporter.Start via initLogRotator. If refreshClosedChannelsCache failed before Start ran, the goroutine dereferenced a nil Logger and panicked. Fix the initialization ordering: move initLogRotator to the top of NewPrometheusExporter so logging is ready before any collector is constructed and before any collector goroutine can run. The constructor now returns an error; a logging init failure is fatal and surfaces on stderr so it stays detectable instead of being silently swallowed. Fixes lightninglabs#129.
c0c640d to
69d9a2d
Compare
|
signed commit |
NewChannelsCollector launched its cache-refresh goroutine at construction time, but the package-global Logger was only initialized later in PrometheusExporter.Start via initLogRotator. If refreshClosedChannelsCache failed before Start ran, the goroutine dereferenced a nil Logger and panicked.
Fix the initialization ordering: move initLogRotator to the top of NewPrometheusExporter so logging is ready before any collector is constructed and before any collector goroutine can run. The constructor now returns an error; a logging init failure is fatal and surfaces on stderr so it stays detectable instead of being silently swallowed.
Fixes #129.