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

Fix geo ip database file leak when processing IP arrays #93177

Merged
merged 4 commits into from
Jan 25, 2023

Conversation

jbaiera
Copy link
Member

@jbaiera jbaiera commented Jan 23, 2023

The DatabaseReaderLazyLoader class keeps track of how many clients are using it at a time. This allows the reader to be cleaned up as soon as the last client using it is complete. This tracking logic takes place by balancing a preLookup method with a postLookup method on each Geo IP processor invocation. The problem arises when processing an array of IPs. Currently the postLookup method is called for each IP in the array, which can cause the reader to decrement incorrectly. If a new database is installed during processor execution the reader can get stuck open, leaving database files on disk when they should be cleaned up.

This PR moves the postLookup call out of the lookup methods in order to correctly decrement the instance counter a single time at the end of the processor call.

@jbaiera jbaiera added >bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v8.6.1 v8.7.0 labels Jan 23, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Jan 23, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Collaborator

Hi @jbaiera, I've created a changelog YAML for you.

@jbaiera
Copy link
Member Author

jbaiera commented Jan 24, 2023

@elasticmachine run elasticsearch-ci/part-1

@masseyke masseyke self-requested a review January 24, 2023 21:47
Copy link
Member

@masseyke masseyke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good catch! It seems odd to me that the call to preLookup happens (we hope) in the supplier (DatabaseReaderLazyLoader lazyLoader = this.supplier.get();) but the call to postLookup is explicit. Since the supplier is given to the constructor, it seems possible that a supplier might not ever even call preLookup. We probably ought to fix that at some point. But that is preexisting weirdness not introduced by this PR (and out of scope for it).

@arteam arteam added v8.6.2 and removed v8.6.1 labels Jan 25, 2023
@jbaiera jbaiera added the auto-backport-and-merge Automatically create backport pull requests and merge when ready label Jan 25, 2023
@jbaiera jbaiera merged commit 14e7096 into elastic:main Jan 25, 2023
@jbaiera jbaiera deleted the fix-geo-ip-database-file-leak branch January 25, 2023 19:14
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.6

jbaiera added a commit to jbaiera/elasticsearch that referenced this pull request Jan 25, 2023
This PR moves the postLookup call out of the lookup methods in order to correctly decrement 
the instance counter a single time at the end of the processor call.
elasticsearchmachine pushed a commit that referenced this pull request Jan 25, 2023
)

This PR moves the postLookup call out of the lookup methods in order to correctly decrement 
the instance counter a single time at the end of the processor call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready >bug :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP Team:Data Management Meta label for data/management team v8.6.2 v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants