GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][broker] Don't let a stalled __change_events reader hang topic policy updates and topic deletion, and close the reader a failed policy cache init leaks by kaminski-dev · Pull Request #27369 · apache/pulsar

Conversation

@kaminski-dev

@kaminski-dev kaminski-dev commented Nov 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #27366

Motivation

A topic policy update writes its event to the namespace's __change_events topic and then waits until the reader of that namespace, on the same broker, has read the event back (untilMessageIdHasBeenRead). That wait had no time limit.

A reader can stay connected and stop delivering, for example when its subscription on the owner broker is bound to a closed cursor (#26924). On that broker, for that namespace:

  • every topic policy update waits for ever, and later updates of the same topic queue behind it in the per-topic sequencer;
  • a topic deletion waits in deleteTopicPolicies() after it fenced the topic, so the topic rejects producers and replicators, and a second deletion fails with Topic is already fenced.

Only unloading <tenant>/<namespace>/__change_events by hand ended it. #26025 bounded the initial load of the policy cache; nothing bounded the reader after that load.

The issue reports a second problem in the same class. When the first read of __change_events fails with an error other than AlreadyClosedException, the reader of the failed initialization stays cached "for the retry to reuse". A broker that owns no bundle of the namespace gets no topic load that retries and no bundle unload that closes the reader. The reader then stays subscribed, with nothing reading from it, until the broker restarts.

Modifications

Stalled reader

 updateTopicPoliciesAsync
   write the event to __change_events
-  wait until the reader has read it back
+  wait until the reader has read it back, for at most topicPoliciesCacheInitTimeoutSeconds
+  on timeout:
+    fail the update with a TimeoutException
+    close the stalled reader, and drop its initialization and the namespace's cached policies
+    if this broker still owns a bundle of the namespace:
+      read __change_events again with a new reader
+      re-notify the namespace's topic-policy listeners once
  • Timeout. The wait reuses topicPoliciesCacheInitTimeoutSeconds (default 60 s, dynamic, 0 disables it), so this adds no setting. I can add a separate setting if you prefer one.
  • The operation fails. The failure releases the updates queued behind it, and PersistentTopic.delete takes its existing error path, which unfences the topic. The event the operation wrote is not rolled back; it takes effect once the new reader has read it.
  • The reader is replaced. The timeout drops the initialization the update had awaited, the namespace's cached policies and the reader in one step inside policyCacheInitMap.compute, and only while that initialization is still the current one, so a newer initialization is never touched.
    • The cached policies cannot be kept. The new reader reads the compacted topic from the start, so it cannot remove a policy that was deleted during the stall and whose tombstone was compacted away.
    • No read sees the cache empty or partly rebuilt. A policy read answers inside compute on the same key, and only from a completed initialization (apart from the existing branch for a namespace being deleted).
    • The reader leaves the cache before the message-handler tracker is closed, also in cleanupFailedPolicyCacheInit. Closing the tracker completes the other waits of the namespace, and an update queued behind one of them starts on the same thread and must not find the old reader cached.
    • The replacement's first pass over __change_events records every event it applies in the message-handler tracker, as a live delivery does. An update whose write was in flight while the reader was replaced then finds its event already read when it registers its wait, instead of timing out on a delivery that never comes (its event is behind the new reader) and retiring the healthy replacement. The wait takes the current initialization and its tracker in one step, and a tracker leaves its map in the same step as the initialization it belongs to, so a timeout retires the generation whose tracker holds the wait.
    • A reader that was replaced or unloaded can still complete a receive it had handed out before it was closed. Every delivery now writes to the caches inside policyCacheInitMap.compute on its namespace, and only while its initialization is still the current one; the replacement and the unload clear the caches inside the same step, so a late delivery either lands before the clearing or is dropped, and cannot put back a policy whose deletion compaction has dropped since. Only the cache maps are touched under that step; the event is decoded before it, and the tombstone written for a pre-Fix messages in TopicPolicies will never be cleaned up #11928 DELETE event moved out of it.
  • An initialization and its reader slot are installed in one step. prepareInitPoliciesCacheAsync used to install the initialization and then create and cache its reader as a separate action. A namespace unload between the two dropped the initialization but found no reader to remove; the reader created afterwards consumed the first event, found its initialization superseded (the guard above), dropped the event, and stayed cached for the next initialization to inherit one event in. The initialization now publishes an empty slot in readerCaches in the same compute step that installs it, the unload removes the reader inside its own step, and the reader is created after the step, outside any lock, and relayed into the slot. An unload either runs before the step (nothing to drop) or after it (the slot is removed and closed, so the reader is closed on arrival).
  • Loaded topics catch up. A broker that still owns a bundle of the namespace reads __change_events again at once, on the namespace's ordered executor like the bundle ownership callbacks. That one initialization re-notifies the topic-policy listeners of the namespace even when topicPolicyListenerReplayEnabled is off. Without it, a loaded topic would keep the policies from before the stall until its next policy update or reload, while the admin API already showed the new ones. The listeners of a topic that had policies and has none after the rebuild first get the null update that a delivered deletion gives them.

Leaked reader

  • A failed initialization now also closes its reader when the broker owns no bundle of the namespace. A broker that serves the namespace keeps the reader for the retry, as before.

Documentation

  • topicPoliciesCacheInitTimeoutSeconds (in ServiceConfiguration, conf/broker.conf and conf/standalone.conf) and topicPolicyListenerReplayEnabled describe the behaviour above.

Not in this PR

These are the other suggestions of #27366. #27368 tracks the first two:

  • A liveness check for a reader that stalls while this broker writes no policy. Such a stall is still found only by the next policy update or topic deletion on the broker. The check is a new periodic mechanism, so it should be a change of its own.
  • Metrics for pending read-back waits and for the update sequencer. pip/README.md asks for a PIP for metric changes.
  • Whether a broker should create a reader at all for a namespace it owns no bundle of. A successful initialization there keeps a working reader, as before.

One limitation remains:

  • The paths that discard an initialization without a reader replacement (init timeout, failed first read, closed reader) keep the cached policies, as they did before this change. A deletion that is compacted away before the retry can stay cached there. (A late delivery of their reader no longer writes to the cache, though: the generation guard covers those paths too.)

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • TopicPoliciesStalledReaderTest (new) wraps the real __change_events reader in one that can stop delivering while it stays open, and can later complete the delivery it withheld, and the writer in one whose result can be held back from the service. Everything else is the production path. It checks that:
    • a policy update fails with a TimeoutException instead of waiting for ever;
    • the stalled reader is closed, and the next update succeeds on a new reader;
    • a loaded topic applies the update that timed out, with no further write;
    • a forced topic deletion fails, the topic accepts a producer again, and a second deletion succeeds;
    • an update queued behind another waiting update succeeds while the reader is replaced;
    • a policy deleted during the stall, whose tombstone is then compacted away, is gone after the replacement;
    • a listener gets the null update for a deletion that the stalled reader withheld;
    • an update whose write is in flight while the reader is replaced completes once the replacement has applied its event, and does not retire the replacement reader;
    • a delivery that the replaced reader had received before the stall, completed after the replacement, does not put back into the rebuilt cache a policy whose deletion was compacted away.
    • an unload that lands after an initialization is installed and before its reader exists leaves no reader for the next initialization, which finds the policy written before; the interrupted initialization's reader is closed. (This guards the one-step shape: on the previous head the reader was created under a lock, so the unload could not be injected there and the test dies by its timeout.)
    • the queued-update test asks the service, through a package-private @VisibleForTesting accessor (pendingReadBackWaits), whether the waiting update has registered its wait before it shortens the timeout.
  • SystemTopicBasedTopicPoliciesServiceTest#testFailedInitClosesReaderWhenBrokerOwnsNoBundleOfNamespace fails the first read of a reader in two namespaces. The broker keeps the reader of the namespace it owns a bundle of, and closes the reader of the namespace it owns no bundle of.

Before and after, with the same command:

./gradlew :pulsar-broker:test -PtestRetryCount=0 -PtestFailFast=false \
  --tests "org.apache.pulsar.broker.service.TopicPoliciesStalledReaderTest" \
  --tests "org.apache.pulsar.broker.service.SystemTopicBasedTopicPoliciesServiceTest.testFailedInitClosesReaderWhenBrokerOwnsNoBundleOfNamespace"
Result
master (bb6bd03) with only the test changes 8 tests, 8 failed: the updates and the deletions are still waiting after the timeout, and the leaked reader is still cached
31a28d5 (the previous head of this PR) with only the two new tests 2 tests, 2 failed: the in-flight update timed out after 2 s on the healthy replacement, and the delivery completed after the replacement put maxConsumerPerTopic=6 back into the rebuilt cache
8c0aec1 (the previous head of this PR) with only the unload test 1 test, 1 failed: dies by its timeout, since the unload cannot be injected where the reader is created under a lock
this branch 11 tests, 11 passed, in 5 consecutive runs

The topic policy and system topic test classes of pulsar-broker pass as well (15 classes, 360 tests, no failures, -PtestRetryCount=0): SystemTopicBasedTopicPoliciesServiceTest, TopicPolic* in broker.service, InmemoryTopicPoliciesServiceServiceTest, LegacyAwareTopicPoliciesServiceTest, ReplicatorTopicPoliciesTest, BrokerServiceTopicDeletionTest, broker.systopic.*, and TopicPoliciesTest, TopicPoliciesUpdateTest and MetadataStoreTopicPoliciesTest in broker.admin. ./gradlew sanityCheck passes.

Does this pull request potentially affect one of the following parts:

  • The default values of configurations (no new option and no changed default: the existing topicPoliciesCacheInitTimeoutSeconds, default 60 s, now also bounds how long a topic policy update or a topic deletion waits for the read-back, which was unbounded)
  • The threading model (a wait that times out completes on the broker's scheduled pulsar executor, as the initialization timeout of [fix][broker] Don't let a stuck or aborted topic policies cache init make a namespace's topics unloadable #26025 does, instead of on the reader's callback thread)

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kaminski-dev added 16 commits November 5, 2026 13:25
@kaminski-dev
Add a failing test for a topic policy update that waits on a stalled …
fda10b2
…reader

The update writes its event and then waits, without a time limit, until the
namespace's __change_events reader has read the event back. The test stalls
the reader and expects the update to fail with a timeout.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Time out a topic policy update whose event the reader never reads back
1fc6cbb
Bound the wait in untilMessageIdHasBeenRead with
topicPoliciesCacheInitTimeoutSeconds. The update then fails with a
TimeoutException, which releases the updates queued behind it in the
per-topic sequencer and lets a topic deletion take its existing error path.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Add a failing test for replacing a stalled topic policies reader
90528be
After a read-back timeout the reader stays in place, so every later update
in the namespace times out as well.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Close the stalled topic policies reader after a read-back timeout
b110c65
The timeout shows that the reader of the namespace stopped delivering.
Close it through the identity-guarded cleanup, so the next initialization
reads __change_events with a fresh reader.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Add a failing test for a loaded topic that misses the update that tim…
f19f2ea
…ed out

Closing the stalled reader is not enough for a broker that still serves
topics of the namespace: nothing reads __change_events again until the next
policy access, and a new initialization does not notify loaded topics.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Read __change_events again after replacing a stalled reader
9b5ade3
A broker that still owns a bundle of the namespace initializes the policy
cache again right after it closed the stalled reader, and that
initialization re-notifies the topic-policy listeners. The topics loaded on
the broker then apply the events the stalled reader withheld, including the
event of the update that timed out.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Test that a topic deletion does not leave the topic fenced when the r…
1723733
…eader stalls

The deletion waits for the event that deletes the topic's policies. With
the read-back timeout it fails, the topic accepts producers again, and a
second deletion succeeds on the replacement reader.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Add a failing test for the reader leaked by a failed policy cache init
f439abf
When the first read of a namespace's __change_events fails on a broker
that owns no bundle of the namespace, the reader stays cached and
subscribed: no topic load retries the initialization and no bundle unload
closes it.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Close the reader when a policy cache init fails for a namespace the b…
68ba342
…roker does not serve

The reader of a failed initialization is kept for the retry of the next
topic load, and the bundle unload closes it. A broker that owns no bundle
of the namespace gets neither, so close the reader with the failed
initialization there.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Document that topicPoliciesCacheInitTimeoutSeconds also bounds the re…
946400a
…ad-back wait

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Add a failing test for an update that starts while the stalled reader…
0652fd8
… is replaced

Closing the message-handler tracker ends the other waits of the namespace,
and an update queued behind one of them starts on the same thread, before
the stalled reader has left the reader cache. It initializes the namespace
with that reader and fails.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Drop the reader from the cache before closing the message-handler tra…
ad90fbc
…cker

An update that starts while cleanupFailedPolicyCacheInit closes the tracker
initializes the namespace again. With the reader still cached it got the
reader that the cleanup closes right afterwards.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Start the re-initialization on the namespace's ordered executor
6145880
The bundle ownership callbacks run there, so a bundle unload can no longer
land between the ownership check and the start of the initialization.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Document the listener replay after a reader replacement and that a ti…
be997d4
…med-out event is kept

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Tighten the stalled-reader and leaked-reader tests
4cf913c
Shorten the timeout only once the readers are stalled, share the two-step
stall assertion with the deletion test, and drive the leaked-reader test
through a bundle load and a policy read with the failing reader injected at
the reader factory.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Make the stalled-reader tests independent of host speed
ebbfa51
Restore the default timeout on the thread that reports the stall, before the
reader is replaced, and check that both updates are waiting before the first
one times out.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
kaminski-dev marked this pull request as ready for review November 5, 2026 13:36
codelipenghui
codelipenghui requested changes Nov 5, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Code Review request for changes for commit ebbfa51.

Summary:

The timeout and reader cleanup address the reported hangs, and all 12 selected PR/existing tests passed. Request changes: recovery can retain compacted-away policies and omit deletion notifications. Two review-only regression probes reproduced these distinct failures with production code unchanged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

kaminski-dev added 4 commits November 6, 2026 07:25
@kaminski-dev
Add failing tests for policies deleted while the reader was stalled
e6e8679
After the reader is replaced, a policy whose deletion was compacted away
is still in the policy cache, and a deletion that the replacement reader
reads does not reach the topic-policy listeners.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Rebuild the policy cache and replay deletions when a stalled reader i…
b55e6c3
…s replaced

The replacement kept the cached policies and only added what the new reader
read. A policy that was deleted while the reader was stalled, and whose
tombstone was compacted away, stayed cached, and a deletion that the new
reader did read never reached the topic-policy listeners.

Drop the namespace's cached policies in the same step as the stalled
initialization, and tell the listeners of the topics that have no policies
after the rebuild.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Remove the stalled reader from the cache in the same step as its init…
1fc65f5
…ialization

A policy read that started a new initialization right after the stalled one
was dropped could still be handed the old reader. Also name the record for
what it holds, make it immutable, and correct two comments.

Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
Give the compaction test a timeout longer than its own waits
31a28d5
Assisted-by: Claude Code (Claude Fable 5.1)
@kaminski-dev
kaminski-dev requested a review from codelipenghui November 6, 2026 07:13
lhotari
lhotari reviewed Nov 6, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for tackling the hang on a stalled __change_events reader; bounding the read-back wait is the right shape, and the cache rebuild and deletion replay that were asked for earlier are in. The config key reuse is fine (same name, default 60, already dynamic, documented in both conf files and ServiceConfiguration), the timer runs on the broker executor, and the leaked-reader close is correct. I checked the new tests against the production change: with the read-back timer disabled all seven tests in TopicPoliciesStalledReaderTest fail, and with the !ownsBundleOf(namespace) condition reverted testFailedInitClosesReaderWhenBrokerOwnsNoBundleOfNamespace fails. Remaining points: one case where a replacement reader is closed needlessly, one narrow callback race, and a timing assumption in one test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ar-broker/src/test/java/org/apache/pulsar/broker/service/TopicPoliciesStalledReaderTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui requested changes Nov 6, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Code Review request for changes for commit 31a28d5.

Summary:

The follow-up addresses both original regression scenarios: it clears cached policies and replays deletions. However, the rebuild still allows a superseded reader's delayed callback to restore stale entries. Request changes for that remaining race. Current-head tests were not executed: the managed validator ran the preserved older checkout.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui requested changes Nov 6, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Recommendation remains request changes. The original cache-rebuild and deletion-notification gaps are addressed in source, but the previously reported stale-reader callback race remains unresolved. The new discussion also identifies needless replacement of a healthy reader and a timing-dependent test. No commits changed, and no tests were run in this comments-only follow-up.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ar-broker/src/test/java/org/apache/pulsar/broker/service/TopicPoliciesStalledReaderTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

kaminski-dev and others added 4 commits November 6, 2026 21:53
@kaminski-dev @claude
Add failing tests for two races left after a stalled reader is replac…
f0a0840
…ed (apache#27366)

An update whose write is in flight while the reader is replaced has its event
applied by the replacement's first pass over __change_events, but its wait
for the read-back is registered afterwards and nothing completes it: the
update times out, and the timeout then retires the healthy replacement.

A delivery the replaced reader had already received can complete after the
reader is closed. Its callback writes to the cache that the replacement just
cleared, and puts back a policy whose deletion compaction has dropped.

Also make the queued-update test independent of host speed: the update that
has to keep waiting gets a timeout longer than the test, and only the update
that is to report the stall gets the short one.

Assisted-by: Claude Code (Claude Fable 5.1)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kaminski-dev @claude
Record the replacement reader's first pass and drop deliveries of a s…
87a757e
…uperseded reader (apache#27366)

An update whose write was in flight while the stalled reader was replaced
registered its wait for the read-back after the replacement had applied its
event in its first pass over __change_events; the first pass recorded nothing
in the tracker, so the wait timed out and then retired the healthy replacement.
The first pass now records every event it applies, as a live delivery does,
and the wait takes the initialization and the tracker in one step, so a
timeout retires the initialization whose tracker holds the wait.

A reader that was replaced or unloaded can still complete a receive it had
handed out before it was closed, and its callback wrote to the cache after
the replacement had cleared it: a policy whose deletion compaction had dropped
came back, and nothing could remove it again. Every delivery now writes to
the caches inside policyCacheInitMap.compute on its namespace, and only while
its initialization is still current; the replacement and the unload clear the
cache inside the same step, so the write either lands before the clearing or
is dropped. The tombstone that a legacy DELETE event triggers moves out of
that step, so no write to the system topic happens under the lock.

Assisted-by: Claude Code (Claude Fable 5.1)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kaminski-dev @claude
Drop a tracker in the same step as its initialization, and decode eve…
925d041
…nts before the lock (apache#27366)

replaceStalledReader, cleanupFailedPolicyCacheInit and cleanPoliciesCacheInitMap
removed the message-handler tracker after, or before, the step that drops the
initialization. A first pass of a new initialization that started in between
recorded its progress in the tracker about to be closed, and a wait registered
afterwards for an event that pass had applied would time out and retire the
healthy reader. The tracker now leaves its map inside the same compute step as
the initialization (closing it stays outside), so a wait, a first pass and a
timeout always refer to the tracker of one initialization.

Also decode the event before the cache write takes the lock, since decoding
can wait for a schema fetch; name the first pass's stage future for what it
is; and in the tests, build the write-holding factory eagerly, let a held write
be released only once the service has made it, and hold the queued-update
test's waiting update so it registers its wait under the long timeout.

Assisted-by: Claude Code (Claude Fable 5.1)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kaminski-dev @claude
Share the guarded drop of an initialization between its three callers (…
6a39e36
…apache#27366)

replaceStalledReader and cleanupFailedPolicyCacheInit repeated the identity-
guarded step that drops an initialization with its reader and tracker; both
now go through dropInitializationIfCurrent, which takes what else has to go in
the same step. The tracker needs no capture before the step any more: it is
created and removed inside compute() on the namespace only, so whatever is
installed when the guard passes belongs to the initialization being dropped.

Also correct the comment on the pairing of initialization and tracker (the
failed-first-read path keeps the tracker with the reader for the retry), pass
the decoded event to the listener notification instead of decoding it again,
and relay the held write's result through one future in the test harness.

Assisted-by: Claude Code (Claude Fable 5.1)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@kaminski-dev kaminski-dev mentioned this pull request Nov 13, 2026
[Bug][broker] A discarded topic policies cache initialization keeps cached policies whose deletion was compacted away #27612
Closed
3 tasks done
@kaminski-dev @claude
Merge remote-tracking branch 'origin/fix/27366-topic-policies-stuck-r…
ced883f
…eader' into fix/27366-topic-policies-stuck-reader

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@kaminski-dev

kaminski-dev commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @lhotari. Here is what I did with the three items.

  1. I opened [Bug][broker] A discarded topic policies cache initialization keeps cached policies whose deletion was compacted away #27612 for the cached policies that cleanupFailedPolicyCacheInit keeps. I will send a follow-up PR that applies the same atomic drop there after this PR merges.
  2. e78e2c7 fixes the timeout capture the way you suggested. The threads on lines 220 and 687 have the details.
  3. 78e83ff sets READ_TIMEOUT_SECONDS to 1 second. The class now takes about 21 seconds on my machine, down from about 32.

Item 3 needed one more change. topicPoliciesCacheInitTimeoutSeconds also bounds the initialization that follows a reader replacement. The update tests restore the default on the thread that fails their wait, before the broker replaces the reader. The topic deletion test restored it on the test thread, after the admin client had reported the failure. By then the replacement's initialization had started under the short timeout. I delayed the replacement reader by 1.5 seconds with a temporary probe, which I did not commit. That initialization then timed out after 1 second, and the test's second deletion failed with that timeout error. The test now restores the default where the broker deletes the topic's policies, through a hook in the test's service. With the same probe all 10 tests pass, and every replacement starts under the default timeout.

I also merged master. Broker Group 4 failed on ClusterMigrationTest.testClusterMigration with TopicMigratedException. That run tested a merge commit from Nov 7, and #27467 and #27449 fixed the test on master on Nov 9.

@codelipenghui, the commits since your last review address both of its points. 0a3d2a0 installs an initialization and its reader slot in one step, and a482f33 and fdd932f add the test for it. The queued-update test now waits on pendingReadBackWaits, and e78e2c7 closes the window that remained there. Could you take another look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui approved these changes Nov 13, 2026
View reviewed changes
@kaminski-dev
Merge branch 'master' into fix/27366-topic-policies-stuck-reader
aa61bfb
codelipenghui
codelipenghui approved these changes Nov 15, 2026
View reviewed changes
@kaminski-dev
Merge branch 'master' into fix/27366-topic-policies-stuck-reader
297a442
@kaminski-dev

kaminski-dev commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@lhotari @codelipenghui , can we merge the PR or is something else from me required to merge it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui approved these changes Nov 15, 2026
View reviewed changes
@kaminski-dev
Merge branch 'master' into fix/27366-topic-policies-stuck-reader
84d401c
codelipenghui
codelipenghui approved these changes Nov 16, 2026
View reviewed changes
@kaminski-dev
Merge branch 'master' into fix/27366-topic-policies-stuck-reader
4119a77
lhotari
lhotari approved these changes Nov 17, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM. The two follow-up commits are exactly the requested edits, and nothing in the PR's own files changed after them (only master merges).

  • SystemTopicBasedTopicPoliciesService.java:354 now reads topicPoliciesCacheInitTimeoutSeconds before addPendingFuture and passes it to scheduleReadBackTimeout, so a wait that pendingReadBackWaits counts already has its deadline. That closes the window from my earlier threads.
  • The stalled-reader tests use a 1 second timeout and restore the default through an afterNextPolicyDeletion hook on the broker's own deletion, which keeps the replacement reader's initialization under the default timeout.

Nothing else is needed from my side.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kaminski-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lhotari

lhotari commented Nov 17, 2026

Copy link
Copy Markdown
Member

Nothing more is needed from you on my side; the latest changes look good to me. The merge is up to the committers.

kaminski-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari
lhotari merged commit 192d5c7 into apache:master Nov 18, 2026
81 of 83 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kaminski-dev kaminski-dev mentioned this pull request Nov 18, 2026
[fix][broker] Don't return a deleted topic policy after the broker discards a topic policies cache initialization #27664
Merged
11 tasks
lhotari pushed a commit that referenced this pull request Nov 19, 2026
@kaminski-dev @claude @lhotari
[fix][broker] Don't let a stalled __change_events reader hang topic p…
26a9eed
…olicy updates and topic deletion, and close the reader a failed policy cache init leaks (#27369)

Co-authored-by: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 192d5c7)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 19, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
[fix][test] Replace testGetTopicPoliciesWithCleanCache with a namespace unload test #27689
Merged
@lhotari

lhotari commented Nov 21, 2026

Copy link
Copy Markdown
Member

This PR turned a pre-existing test added in #20763 into a flaky test. The test itself isn't great. I've addressed the problem in #27689.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@kaminski-dev @claude @lhotari
[fix][broker] Don't let a stalled __change_events reader hang topic p…
1ceb835
…olicy updates and topic deletion, and close the reader a failed policy cache init leaks (apache#27369)

Co-authored-by: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 192d5c7)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@kaminski-dev @claude @lhotari
[fix][broker] Don't let a stalled __change_events reader hang topic p…
28c7e25
…olicy updates and topic deletion, and close the reader a failed policy cache init leaks (apache#27369)

Co-authored-by: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 192d5c7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lhotari lhotari lhotari approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug][broker] Topic policy updates and topic deletion wait forever when the __change_events reader stops, and a failed policy cache init leaks the reader

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@kaminski-dev @lhotari @codelipenghui
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.