Skip to content

Commit

Permalink
Fix a nil pointer dereference in GetSourceNames() (#541)
Browse files Browse the repository at this point in the history
Fix a nil pointer dereference in `GetSourceNames()`, which happened
quite often for me while developing Quesma - I often start Quesma before
Elastic is fully up, therefore `im.sources` would be nil (failed to load
from Elastic) and `GetSourceNames()` would panic.
  • Loading branch information
avelanarius authored Jul 18, 2024
1 parent d61d294 commit 4e42a9b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions quesma/elasticsearch/index_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ func (im *indexManagement) ReloadIndices() {
}

func (im *indexManagement) GetSources() Sources {
return *im.sources.Load()
if s := im.sources.Load(); s != nil {
return *s
} else {
logger.Warn().Msg("Indices are not yet loaded, returning empty sources.")
return Sources{}
}
}

func (im *indexManagement) GetSourceNames() map[string]bool {
names := make(map[string]bool)
sources := *im.sources.Load()
sources := im.GetSources()
for _, stream := range sources.DataStreams {
names[stream.Name] = true
}
Expand Down

0 comments on commit 4e42a9b

Please sign in to comment.