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

xds: fix header matcher for null value #8503

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

if (value == null) {
return false;
return present() != null && present() == inverted();
Copy link
Member

Choose a reason for hiding this comment

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

This only inverts the value if present() is set. Is that right? It also looks like it has been "simplified" in such a way that makes it harder to see the semantics. I sort of have to make a truth table to make sense of it.

Should it be instead:

return (present() != null && !present()) != inverted();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only inverts the value if present() is set. Is that right?

oh I see the difference between them.

matcher = HeaderMatcher.forExactValue("version", "v1", true);
 assertThat(matcher.matches(null)).isFalse(); // result is different

but isn't this only inverts the value if present() is set?
https://github.com/envoyproxy/envoy/blob/0fae6970ddaf93f024908ba304bbd2b34e997a51/source/common/http/header_utility.cc#L130

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree that is what that code does. Okay. That is subtle. I can see how the documentation could imply that behavior, but it is something to be strongly careful of.

CC @yashykt, @zasweq, this is something we should audit in each language, to make sure we are consistent. (See the envoy link for the precise behavior)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The semantics was that: if value is null, then it first must be a present matcher, then do a invert of the present() because negative present() is a match.
Your semantics is that:
If value is null, base match is true only if it is a present matcher and present() is defined negative, then do invert of the base match.

Copy link
Member

Choose a reason for hiding this comment

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

The key is that "invert the matcher" does not change the behavior for null-ness. It is more SQL-style behavior where col = 'hi' and col <> 'hi' could both be false when col is NULL. All matchers except for present_match require the header to be present.

@YifeiZhuang YifeiZhuang merged commit 7ad7876 into grpc:master Sep 9, 2021
@YifeiZhuang YifeiZhuang deleted the header_match_null branch September 9, 2021 19:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants