Skip to content

Commit 1d9cb22

Browse files
authored
fix(controller): prevent panic on shutdown due to nil pointer (#847)
Prevents following error if controller fails to initialise database on startup (e.g. if it happens to run out of memory when loading the db). ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1a3158e] goroutine 107 [running]: github.com/kagent-dev/kagent/go/internal/database.(*Manager).Close(0xc00024ea00?) /workspace/internal/database/manager.go:144 +0xe github.com/kagent-dev/kagent/go/internal/httpserver.(*HTTPServer).Start.func2() /workspace/internal/httpserver/server.go:110 +0x116 created by github.com/kagent-dev/kagent/go/internal/httpserver.(*HTTPServer).Start in goroutine 104 /workspace/internal/httpserver/server.go:101 +0x288 ``` Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
1 parent 20baa60 commit 1d9cb22

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

go/internal/database/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (m *Manager) Reset(recreateTables bool) error {
141141

142142
// Close closes the database connection
143143
func (m *Manager) Close() error {
144+
if m.db == nil {
145+
return nil
146+
}
147+
144148
sqlDB, err := m.db.DB()
145149
if err != nil {
146150
return err

0 commit comments

Comments
 (0)