Skip to content

Serious memory leak issue #1048

@YenchangChan

Description

@YenchangChan

I had a very serious memory leak when using elasticsearch_exporter to collect metrics, which was causing my app to OOM every few hours in production.
Through the analysis of the pprof tool, the memory usage is relatively large as follows:
Image
After analyzing the code, it is found that in the Run function of the clusterinfo module, a TimeTicker is defined but it is not stopped.

go func(ctx context.Context) {
		if r.interval <= 0 {
			r.logger.Info("no periodic cluster info label update requested")
			return
		}
		ticker := time.NewTicker(r.interval)
		for {
			select {
			case <-ctx.Done():
				r.logger.Info(
					"context cancelled, exiting cluster info trigger loop",
					"err", ctx.Err(),
				)
				return
			case <-ticker.C:
				r.logger.Debug("triggering periodic update")
				r.sync <- struct{}{}
			}
		}
	}(ctx)

When this function is requested on a regular basis, a large number of timers are generated that are not released, causing a serious memory leak.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions