Skip to content

[-] fix QueryMeasurements nil pointer dereference, fixes #766 #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/reaper/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetMonitoredDatabaseByUniqueName(ctx context.Context, name string) (*source
monitoredDbCacheLock.RLock()
defer monitoredDbCacheLock.RUnlock()
md, exists := monitoredDbCache[name]
if !exists || md == nil {
if !exists || md == nil || md.Conn == nil {
return nil, fmt.Errorf("database %s not found in cache", name)
}
return md, nil
Expand Down
1 change: 0 additions & 1 deletion internal/reaper/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ func (r *Reaper) ShutdownOldWorkers(ctx context.Context, hostsToShutDownDueToRol
r.CloseResourcesForRemovedMonitoredDBs(hostsToShutDownDueToRoleChange)
}

// metrics.ControlMessage notifies of shutdown + interval change
func (r *Reaper) reapMetricMeasurements(ctx context.Context, md *sources.SourceConn, metricName string) {
hostState := make(map[string]map[string]string)
var lastUptimeS int64 = -1 // used for "server restarted" event detection
Expand Down
10 changes: 3 additions & 7 deletions internal/sources/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,16 @@ func (mds SourceConns) SyncFromReader(r Reader) (newmds SourceConns, err error)
return nil, err
}
newmds, err = srcs.ResolveDatabases()
for _, newMD := range newmds {
for i, newMD := range newmds {
md := mds.GetMonitoredDatabase(newMD.Name)
if md == nil {
continue
}
if reflect.DeepEqual(md.Source, newMD.Source) {
// keep the existing connection if the source is the same
newMD.Conn = md.Conn
newMD.ConnConfig = md.ConnConfig
// replace with the existing connection if the source is the same
newmds[i] = md
continue
}
if md.Conn != nil {
md.Conn.Close()
}
}
return newmds, err
}
1 change: 0 additions & 1 deletion internal/sources/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ func TestMonitoredDatabases_SyncFromReader(t *testing.T) {
assert.NotNil(t, mdbs, "ResolveDatabases() = nil, want not nil")
// pretend that we have a connection
mdbs[0].Conn = db
db.ExpectClose()
// sync the databases and make sure they are the same
newmdbs, _ := mdbs.SyncFromReader(reader)
assert.NotNil(t, newmdbs)
Expand Down
Loading