Skip to content
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

nsqd: fix nil pointer when memstats enabled #911

Merged
merged 1 commit into from
Jun 21, 2017
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
4 changes: 2 additions & 2 deletions nsqd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,11 @@ func (s *httpServer) doStats(w http.ResponseWriter, req *http.Request, ps httpro
Health string `json:"health"`
StartTime int64 `json:"start_time"`
Topics []TopicStats `json:"topics"`
Memory *memStats `json:"memory"`
Memory memStats `json:"memory"`
}{version.Binary, health, startTime.Unix(), stats, ms}, nil
}

func (s *httpServer) printStats(stats []TopicStats, ms *memStats, health string, startTime time.Time, uptime time.Duration) []byte {
func (s *httpServer) printStats(stats []TopicStats, ms memStats, health string, startTime time.Time, uptime time.Duration) []byte {
var buf bytes.Buffer
w := &buf
now := time.Now()
Expand Down
4 changes: 2 additions & 2 deletions nsqd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type memStats struct {
GCTotalRuns uint32 `json:"gc_total_runs"`
}

func getMemStats() *memStats {
func getMemStats() memStats {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)

Expand All @@ -170,7 +170,7 @@ func getMemStats() *memStats {
copy(gcPauses, ms.PauseNs[:length])
sort.Sort(gcPauses)

return &memStats{
return memStats{
ms.HeapObjects,
ms.HeapIdle,
ms.HeapInuse,
Expand Down
2 changes: 1 addition & 1 deletion nsqd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s Uint64Slice) Less(i, j int) bool {
}

func (n *NSQD) statsdLoop() {
var lastMemStats *memStats
var lastMemStats memStats
var lastStats []TopicStats
ticker := time.NewTicker(n.getOpts().StatsdInterval)
for {
Expand Down