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

Json validator hardening #234

Closed
wants to merge 2 commits into from

Conversation

hamnis
Copy link
Contributor

@hamnis hamnis commented Apr 21, 2023

If the json validator encounters a schema which exists, but has the wrong meta-schema, the current implementation will crash hard.

This pull request fixes that issue by wrapping all calls to the underlying library in Either.catchNonFatal

If the json validator encounters a schema which exists, but has the wrong meta-schema, the current implementation will crash hard.

This pull request fixes that issue by wrapping all calls to the underlying library in Either.catchNonFatal
@hamnis hamnis force-pushed the fix-unexpected-valid-schema branch from 246ada6 to f2b3195 Compare April 21, 2023 09:14
@istreeter
Copy link
Contributor

Hi @hamnis, I'll explain why I'm undecided about merging this change.

First, I'll give a bit of background for the original issue you describe...

If the json validator encounters a schema which exists, but has the wrong meta-schema, the current implementation will crash hard.

This problem you're referring to got addressed by merging #238. The problem with the wrong meta-schema was causing the json-validator to do a http lookup at a point in the code where we had not anticipated any I/O. So we addressed it by preventing the json-validator from following references to external URLs.

Also, the Enrich application never had a hard crash. The old error was caught on this line of Enrich, and it would generate a failed event.

The lag (slow processing) we saw with Enrich was entirely because of json-validator doing a slow http lookup for each event. Even if we wrapped this lookup in a Either.catchNonFatal, then it would not have prevented this slow lookup, and slow processing of events.


Anyway, back to the current PR.....

The call we make to schema.validate(...) is supposed to be a pure function (no I/O) that always returns a result. If it ever throws an exception then something very unexpected has happened!

Now of course, exceptions can always happen. So we have a choice to either catch the exception immediately (like your in PR) or we let the exception bubble up and we catch it here, which is what we've been doing so far.

The main reason to catch the exception early (like your PR) is that we create a SchemaViolation type of failed event, described here. It's a slightly more informative type of failed event, and it can be recovered by our standard event recovery processes. If we catch the exception later then we create a GenericError type of failed event.

The main reason to catch the exception later is that we also send the exception to Sentry which means Snowplow engineers get a notification and we know something bad has happened. And to re-iterate, any exception thrown from schema.validate is unexpected, so I think it's better to treat it as a genuine error in the code instead of treating as a problem with the data.

@hamnis
Copy link
Contributor Author

hamnis commented Jun 29, 2023

Catching this in the library would allow other uses which does not trust java code to not throw exceptions. Now users may have to guard against that in the same way as enrich does.

@hamnis
Copy link
Contributor Author

hamnis commented Jul 12, 2023

Closing due to lack of interest

@hamnis hamnis closed this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants