Skip to content
Latchkey

Go "signal SIGSEGV: segmentation violation" in Tests - Fix in CI

The test binary received a SIGSEGV - it accessed memory it should not. In pure Go this is almost always a nil dereference the runtime reports; with cgo or unsafe, it can be a genuine bad memory access in C code.

What this error means

A test run aborts with signal SIGSEGV: segmentation violation followed by a stack trace and a [signal SIGSEGV: ... addr=0x0 pc=...] line. addr=0x0 strongly suggests a nil pointer.

go test output
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x...]

goroutine 6 [running]:
	app.(*Server).Handle(...)
	/app/server.go:52

Common causes

A nil pointer dereference

With addr=0x0, the code dereferenced a nil pointer, interface, or map - the most common SIGSEGV in pure Go.

A bad cgo or unsafe access

cgo passing an invalid pointer to C, or unsafe.Pointer arithmetic gone wrong, causes a real segfault in native code.

How to fix it

Trace the nil dereference and guard it

  1. Read the stack frame just under the SIGSEGV line - that is where the bad access happened.
  2. Add a nil check (or initialize the value) before the dereference.
  3. Cover the nil path with a test so it cannot regress.

Inspect cgo / unsafe usage

When cgo or unsafe is involved, verify pointers are valid for the C call and not freed or moved.

Terminal
go vet ./...                # flags some unsafe.Pointer misuse
go test -race ./...         # surfaces memory issues with cgo

How to prevent it

  • Initialize pointers/interfaces before use and check for nil at boundaries.
  • Follow the cgo pointer rules and run go vet on unsafe code.
  • Add tests for nil and error paths, not just the happy path.

Frequently asked questions

What causes ""signal SIGSEGV""?
With addr=0x0, the code dereferenced a nil pointer, interface, or map - the most common SIGSEGV in pure Go.
How do I fix "signal SIGSEGV"?
Trace the nil dereference and guard it

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card