osquery / osquery-go

Go bindings for osquery
MIT License
386 stars 78 forks source link

Make `ExtensionManagerServer.Shutdown` idempotent #117

Closed lucasmrod closed 10 months ago

lucasmrod commented 10 months ago

The change in dbeefc07d76e3edaf614647a20cc588c1b4f47e4 causes nil dereference panics when calling ExtensionManagerServer.Shutdown more than once.

Here's a stack trace of the panic without the fix:

=== RUN   TestShutdownBasic
--- FAIL: TestShutdownBasic (0.02s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x11ea684]

goroutine 6 [running]:
testing.tRunner.func1.2({0x121b320, 0x1438880})
        /Users/luk/go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
        /Users/luk/go/src/testing/testing.go:1548 +0x397
panic({0x121b320?, 0x1438880?})
        /Users/luk/go/src/runtime/panic.go:914 +0x21f
github.com/osquery/osquery-go.(*ExtensionManagerServer).Shutdown(0xc00010ef00, {0xc0001544e0?, 0x0?})
        /Users/luk/fleetdm/git/forks/osquery-go/server.go:318 +0xa4
github.com/osquery/osquery-go.TestShutdownBasic(0xc0001544e0)
        /Users/luk/fleetdm/git/forks/osquery-go/server_test.go:218 +0x345
testing.tRunner(0xc0001544e0, 0x12888b0)
        /Users/luk/go/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
        /Users/luk/go/src/testing/testing.go:1648 +0x3ad
exit status 2
FAIL    github.com/osquery/osquery-go   0.683s