Repository navigation
fix flaky-test: AuthorizationTest.simple - #9740
Conversation
|
@315157973 This won't fix #9711 . I have put the explanation about the thread safety issue as a comment in #9711 (comment) . |
|
The issue in #9711 is most likely different than the issue which makes |
|
I created an alternative fix which fixes a problem with the test itself: #9746 . I put some notes in the description about the relation to this fix.
I guess this explains why it passed in some cases. It's odd that the behavior is so nondeterministic. Why does the serialization get used at all? I had the impression that there's a local cache that will be used if the entries are available locally, however I haven't checked that aspect. btw. The null value for the role shouldn't be a normal case. The fix in #9746 fixes the test itself that was invalid. |
As long as it is serialized and deserialized once, it will become a hashMap. Because zk update takes time, sometimes it is still TreeMap locally. |
|
I am fine with having the HashMap and use it consistently. This is definitely a good idea. by the way I share @lhotari concerns, we should add explicit checks about security/auth data structures and consistency of the runtime environment. so probably the best is to have both of the two patches merged. |
| namespaceResources().set(path(POLICIES, namespaceName.toString()), (policies) -> { | ||
| if (!policies.auth_policies.destination_auth.containsKey(topicUri)) { | ||
| policies.auth_policies.destination_auth.put(topicUri, new TreeMap<String, Set<AuthAction>>()); | ||
| policies.auth_policies.destination_auth.put(topicUri, new HashMap<>()); |
There was a problem hiding this comment.
why don't we use Maps.newHashMap ?
Fixes apache#9709 ### Motivation ``` Caused by: java.lang.NullPointerException at java.util.TreeMap.getEntry(TreeMap.java:347) ``` From the stack trace, it is caused by the key read by `TreeMap` being null. Therefore, the role must be null. ``` //PulsarAuthorizationProvider.java:404 Map<String, Set<AuthAction>> namespaceRoles = policies.get().auth_policies.namespace_auth; Set<AuthAction> namespaceActions = namespaceRoles.get(role); ``` According to the code, the role is read through `httpRequest.getAttribute` in `PulsarWebResource#clientAppId`, so it is normal to be null. Although the role is null, why do unit tests pass occasionally? I added logs and found that the implementation class of Map is not always TreeMap, but occasionally HashMap. When it is a HashMap, no error will be reported if the key is null. This problem is caused by Jackson's serialization. I checked AuthPolicies, all Maps are initialized as TreeMap, but we have never used any features of TreeMap. In order to avoid serialization problems elsewhere, I changed TreeMap to HashMap. Another way is to add the annotation @JsonDeserialize(as = TreeMap.class), and then make the judgment that the key is null. Why was TreeMap used here? May need @merlimat to help explain.
Fixes #9709 ``` Caused by: java.lang.NullPointerException at java.util.TreeMap.getEntry(TreeMap.java:347) ``` From the stack trace, it is caused by the key read by `TreeMap` being null. Therefore, the role must be null. ``` //PulsarAuthorizationProvider.java:404 Map<String, Set<AuthAction>> namespaceRoles = policies.get().auth_policies.namespace_auth; Set<AuthAction> namespaceActions = namespaceRoles.get(role); ``` According to the code, the role is read through `httpRequest.getAttribute` in `PulsarWebResource#clientAppId`, so it is normal to be null. Although the role is null, why do unit tests pass occasionally? I added logs and found that the implementation class of Map is not always TreeMap, but occasionally HashMap. When it is a HashMap, no error will be reported if the key is null. This problem is caused by Jackson's serialization. I checked AuthPolicies, all Maps are initialized as TreeMap, but we have never used any features of TreeMap. In order to avoid serialization problems elsewhere, I changed TreeMap to HashMap. Another way is to add the annotation @JsonDeserialize(as = TreeMap.class), and then make the judgment that the key is null. Why was TreeMap used here? May need @merlimat to help explain. (cherry picked from commit b2796f3)
Fixes #9709
Motivation
From the stack trace, it is caused by the key read by
TreeMapbeing null. Therefore, the role must be null.According to the code, the role is read through
httpRequest.getAttributeinPulsarWebResource#clientAppId, so it is normal to be null.Although the role is null, why do unit tests pass occasionally?
I added logs and found that the implementation class of Map is not always TreeMap, but occasionally HashMap.
When it is a HashMap, no error will be reported if the key is null. This problem is caused by Jackson's serialization.
I checked AuthPolicies, all Maps are initialized as TreeMap, but we have never used any features of TreeMap.
In order to avoid serialization problems elsewhere, I changed TreeMap to HashMap.
Another way is to add the annotation @JsonDeserialize(as = TreeMap.class), and then make the judgment that the key is null.
Why was TreeMap used here? May need @merlimat to help explain.