-
Notifications
You must be signed in to change notification settings - Fork 82
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 crash of pipeline due to NPE when lookup in DB with custom fields #225
Conversation
7142552
to
9ff6999
Compare
04989e5
to
e23d4a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, thanks for fixing it!
I'm fine as it's, but my suggestion would be extending the GeoIp2Exception
exception, providing the custom message and cause. This way, we could avoid repeating the same code block with comment and message in every database access attempt. Having the original cause on the exception wrapper would also be useful for troubleshooting and to ensure the NPE is in fact the same error we're handling (invalid custom fields), and not a new one.
// This exception could raise during the processing of datapoint with custom fields, check out
// for more details https://github.com/logstash-plugins/logstash-filter-geoip/issues/226
static class GeoIp2InvalidCustomFieldException extends GeoIp2Exception {
public GeoIp2InvalidCustomFieldException(Throwable cause) {
super("invalid custom field", cause);
}
}
CountryResponse response;
try {
response = databaseReader.country(ipAddress);
} catch (NullPointerException e) {
throw new GeoIp2InvalidCustomFieldException(e);
}
…g invalid custom fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
There's a related bug in this area - if the source field is an empty list, the
|
Release notes
Avoid to crash pipelines when lookup a database with customised fields.
What does this PR do?
Protect the
handleEvent
method from NPE generated in the MAxMind GeoIP reader library.That NPE happens when fetching data that contains customised attributes, this PR protects from NPE and return a lookup error so that the Event can be tagged with failure.
Why is it important/What is the impact to the user?
Permit the user to handle an unexpected error (through event tag) instead of crashing the pipeline, when the data lookup encounter a customised field in the DB.
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
How to test this PR locally
Follow the steps listed in #226
Related issues
Use cases
Screenshots
Logs
Before the fix:
After the fix: