apache / apache/pulsar

[Bug] MetadataStoreTopicPoliciesService: policy change events may be lost or transiently return null

Open
#26,453 1 comment 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before reporting

- [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Read release policy

- [x] I understand that [unsupported versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions) don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

### User environment

built from master

### Issue Description

1. Change events lost after ZK reconnection
The service relies on ZK watches. Any policy update that occurs during a transient ZK disconnection is silently dropped — downstream listeners never receive `onUpdate`. `SystemTopicBasedTopicPoliciesService` avoids this by resuming its `__change_events` reader from the last consumed offset.
2. Transient null during policy update
`handleNotification` calls `cache.invalidate(path)` before re-fetching. During this window, `getTopicPoliciesIfExists` (which calls `MetadataCache.getIfCached`) returns `null` instead of the old value. `SystemTopicBasedTopicPoliciesService` always overwrites in-memory entries atomically, so callers see old or new — never null.
In single-cluster deployments (`metadataStoreUrl == configurationMetadataStoreUrl`), both listeners fire on the same store instance, calling `invalidate` twice and doubling the null window.

### Error messages

```text

```

### Reproducing the issue

Any update to the `MetadataStoreTopicPoliciesService` topic policies.

### Additional information

_No response_

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start by reading MetadataStoreTopicPoliciesService, especially handleNotification and getTopicPoliciesIfExists, then compare its behavior with SystemTopicBasedTopicPoliciesService. Reproduce a topic-policy update across a ZooKeeper reconnection and in a single-cluster deployment; done means updates are not lost and callers do not transiently observe null.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.