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

BulkIndexer memory leak? #956

Open
JAndritsch opened this issue Feb 15, 2025 · 3 comments
Open

BulkIndexer memory leak? #956

JAndritsch opened this issue Feb 15, 2025 · 3 comments

Comments

@JAndritsch
Copy link

JAndritsch commented Feb 15, 2025

I'm observing what appears to be a memory leak when using a BulkIndexer. I noticed that my application's memory was growing rapidly as usage of the BulkIndexer increased. I thought it was maybe my own code in how I was handling the bulk index items, but I commented out the entire thing and was able to replicate the issue by simply triggering a scenario that ran this code successively:

indexer, _ := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
	Index:  "some-index",
	Client: s.client, // a pointer to elasticsearch.Client
})

ctx := context.Background()

indexer.Close(ctx)

You don't even need to add any items. Just triggering this code multiple times results in a massive increase in memory after a few iterations. My application uses like 8mb of memory after startup. Simply invoking the above code 3-4 times causes that to jump to 160mb. Another time after that and it goes up to 300+mb.

I am using package version v8.17.1.

@JAndritsch JAndritsch changed the title BulkIndexer memory leak BulkIndexer memory leak? Feb 15, 2025
@JAndritsch
Copy link
Author

JAndritsch commented Feb 15, 2025

Update: It seems like memory usage drops down eventually over time (several minutes past the point memory peaks), but the initial spike from ~8mb to 300mb is pretty unexpected. Could there be some internal resource that's eventually timing out and freeing up after some amount of time?

@JAndritsch
Copy link
Author

JAndritsch commented Feb 15, 2025

It does seem related to indexer.Close(ctx). If I comment that out and just nil out the ref to the indexer then memory usage doesn't climb unexpectedly. But if I keep indexer.Close(ctx) and still attempt to nil out the indexer ref, I see the unexpected memory usage spike.

So basically...

This leaks:

indexer, _ := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
	Index:  "some-index",
	Client: s.client, // a pointer to elasticsearch.Client
})

ctx := context.Background()

indexer.Close(ctx)

This does not leak:

indexer, _ := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
	Index:  "some-index",
	Client: s.client, // a pointer to elasticsearch.Client
})

ctx := context.Background()

//indexer.Close(ctx)

@JAndritsch
Copy link
Author

Looks like there's already a PR for this: #701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant