Repository navigation
Labels
area/brokertype/enhancementThe enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Description
Search before asking
- I searched in the issues and found nothing similar.
Motivation
There is access to auth related data that is not obviously thread safe.
Here are two methods called by other threads:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Lines 443 to 456 in 8049690
| private CompletableFuture<Boolean> isTopicOperationAllowed(TopicName topicName, String subscriptionName, | |
| TopicOperation operation) { | |
| if (service.isAuthorizationEnabled()) { | |
| AuthenticationDataSource authDataSource = | |
| new AuthenticationDataSubscription(authenticationData, subscriptionName); | |
| AuthenticationDataSource originalAuthDataSource = null; | |
| if (originalAuthData != null) { | |
| originalAuthDataSource = new AuthenticationDataSubscription(originalAuthData, subscriptionName); | |
| } | |
| return isTopicOperationAllowed(topicName, operation, authDataSource, originalAuthDataSource); | |
| } else { | |
| return CompletableFuture.completedFuture(true); | |
| } | |
| } |
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Lines 779 to 797 in 8049690
| public void refreshAuthenticationCredentials() { | |
| AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState; | |
| if (authState == null) { | |
| // Authentication is disabled or there's no local state to refresh | |
| return; | |
| } else if (getState() != State.Connected || !isActive) { | |
| // Connection is either still being established or already closed. | |
| return; | |
| } else if (!authState.isExpired()) { | |
| // Credentials are still valid. Nothing to do at this point | |
| return; | |
| } else if (originalPrincipal != null && originalAuthState == null) { | |
| log.info( | |
| "[{}] Cannot revalidate user credential when using proxy and" | |
| + " not forwarding the credentials. Closing connection", | |
| remoteAddress); | |
| return; | |
| } |
Solution
It would be better to update the paradigm to ensure correct access of the data. I think we should avoid making the variables volatile and instead make them only accessed from the netty event loop.
Alternatives
Make the variables volatile.
Anything else?
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
Metadata
Metadata
Assignees
Labels
area/brokertype/enhancementThe enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Activity
sunheyi6 commentedon Feb 7, 2023
@michaeljmarshall the first method that causes thread insecurity should be this code
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Lines 1065 to 1069 in 8049690
Both methods do cause thread safety issues
[fix][broker] Make ServerCnx#originalAuthData volatile (#19507)
[fix][broker] Make ServerCnx#originalAuthData volatile (#19507)
[fix][broker] Make ServerCnx#originalAuthData volatile (apache#19507)
[fix][broker] Make ServerCnx#originalAuthData volatile (#19507)
[fix][broker] Make ServerCnx#originalAuthData volatile (#19507)
[fix][broker] Make ServerCnx#originalAuthData volatile (#19507)