[fix][fn] Avoid scheduler shutdown deadlock - #26557
Open
lhotari wants to merge 1 commit into
Open
Conversation
Assisted-by: Codex (GPT-6)
lhotari
requested review from
Technoboy-,
dao-jun,
david-streamlio,
merlimat and
nodece
September 12, 2026 20:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Broker Group 2 in PR #26547 hit its one-hour timeout during
PulsarFunctionTlsTest.tearDown. The uploaded JVM dump reports a Java-level deadlock:SchedulerManagermonitor insideclose()and waits forschedulerLock.worker-scheduler-0holdsschedulerLockwhile runninginvokeScheduler()and waits for the same monitor ingetCurrentAvailableWorkers().This can also block function-worker shutdown or loss of leadership when scheduling is active.
Modifications
Acquire
schedulerLockbefore entering the manager's synchronized block inclose(), matching the order used by scheduling. Retain mutual exclusion withinitialize()and keep executor and producer shutdown protected against concurrent scheduling.Add a bounded regression test that holds the exposed scheduler lock, waits until shutdown queues for it, and checks that membership queries can still finish. It also verifies that the producer remains open until the scheduler lock is released, then closes successfully. Cleanup releases the lock even on failure, so the test detects the inversion without hanging the test JVM.
Verifying this change
Make sure that the change passes the CI checks.
The new regression test fails on the original implementation with
TimeoutExceptionwhile waiting for the membership query.SchedulerManagerTestandLeaderServiceTestpass with retries disabled: 27 invocations, including ten repetitions of the regression test. The temporary repetition setting was removed afterward.PulsarFunctionTlsTestpasses both tests with retries disabled, including teardown../gradlew quickCheckpasses.Does this pull request potentially affect one of the following parts:
The existing locks and lifecycle serialization are retained; only shutdown's lock acquisition order changes.