Skip to content

[Bug]: Panic / Nil pointer dereference in internal/hub/systems/system.go during tests #1950

@arunoruto

Description

@arunoruto

Welcome!

  • I have read the Documentation
  • I have checked the Common Issues Guide and my problem was not mentioned there.
  • I have searched open and closed issues and my problem was not mentioned before.
  • I have verified I am using the latest version available. You can check the latest release here.

Component

Hub

Problem Description

During the Nix build process on Apple Silicon (Darwin/ARM64), the test suite for github.com/henrygd/beszel/internal/alerts consistently fails with a nil pointer dereference.

The panic occurs in a background goroutine started by StartUpdater. The stack trace shows it failing inside the PocketBase RecordQuery core. Interestingly, this issue does not seem to reproduce on x86_64 Linux/Darwin builds, suggesting a potential race condition that is more susceptible to the ARM memory model or specific to how Nix handles ARM sandboxing.

I have found that wrapping the logic in a recover() allows the build to finish, but the underlying nil dereference in getRecord needs an architectural fix.

  postPatch = ''
    substituteInPlace internal/hub/systems/system.go \
      --replace-fail "func (sys *System) StartUpdater() {" "func (sys *System) StartUpdater() { defer func() { recover() }();"
  '';

Expected Behavior

The test suite should complete without a runtime panic. The StartUpdater function should safely handle cases where the underlying PocketBase app or record is not available.

Steps to Reproduce

Run nix build -L nixpkgs#beszel on an Apple-Silicon device.
It will fail with the following error message:

beszel> Running phase: checkPhase
beszel> ok      github.com/henrygd/beszel/agent 1.782s
beszel> ok      github.com/henrygd/beszel/agent/deltatracker    0.328s
beszel> ok      github.com/henrygd/beszel/agent/health  0.357s
beszel> ok      github.com/henrygd/beszel/agent/utils   0.331s
beszel> panic: runtime error: invalid memory address or nil pointer dereference
beszel> [signal SIGSEGV: segmentation violation code=0x2 addr=0xb0 pc=0x101467140]
beszel>
beszel> goroutine 38652 [running]:
beszel> github.com/pocketbase/pocketbase/core.(*BaseApp).RecordQuery(0x6d7eee754008, {0x102a41b40?, 0x6d7eee446008?})
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/vendor/github.com/pocketbase/pocketbase/core/record_query.go:38 +0x70
beszel> github.com/pocketbase/pocketbase/core.(*BaseApp).FindRecordById(0x6d7eee754008, {0x1028b7480?, 0x102a76260?}, {0x6d7eedefeee0, 0xf}, {0x0, 0x0, 0x1015f1d58?})
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/vendor/github.com/pocketbase/pocketbase/core/record_query.go:223 +0x78
beszel> github.com/henrygd/beszel/internal/hub/systems.(*System).getRecord(0x6d7eee63f0a0)
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/internal/hub/systems/system.go:347 +0x50
beszel> github.com/henrygd/beszel/internal/hub/systems.(*System).setDown(0x6d7eee63f0a0, {0x102a7d940, 0x6d7eee692550})
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/internal/hub/systems/system.go:362 +0x94
beszel> github.com/henrygd/beszel/internal/hub/systems.(*System).StartUpdater(0x6d7eee63f0a0)
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/internal/hub/systems/system.go:88 +0xc4
beszel> created by github.com/henrygd/beszel/internal/hub/systems.(*SystemManager).AddSystem in goroutine 37891
beszel>         /nix/var/nix/builds/nix-71066-3105078627/source/internal/hub/systems/system_manager.go:253 +0x17c
beszel> FAIL    github.com/henrygd/beszel/internal/alerts       63.711s
beszel> FAIL

OS / Architecture

MacOS/arm

Beszel version

0.18.7

Installation method

Nix

Configuration

Hub Logs

Agent Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions