[fix] Restore interrupt status in InterruptedException catch blocks - #26710
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
TimurRakhmatullin86 wants to merge 1 commit into
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
When catching InterruptedException, the interrupt flag on the current thread is cleared by the JVM. Code that catches this exception must restore the flag by calling Thread.currentThread().interrupt() before re-throwing or returning, otherwise upstream code (and the thread's own interrupt-driven shutdown logic) cannot detect that an interrupt occurred. This is a well-documented Java best practice (see Java Concurrency in Practice, section 7.1.2, and the java.lang.InterruptedException Javadoc). This commit fixes 35 catch blocks across 31 files in the following modules where the interrupt status was silently swallowed: - pulsar-broker (service, loadbalance, namespace, admin, web, compaction, transaction, tools, zookeeper) - pulsar-broker-common (authorization, authentication, bookie) - pulsar-common (FileUtils, FutureUtil) - managed-ledger (ManagedLedgerImpl) - pulsar-metadata (bookkeeper integration, ZKSessionWatcher, TableView) - pulsar-proxy (ProxyStats) - pulsar-transaction (MLTransactionLogImpl) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
When Java code catches
InterruptedException, the JVM automatically clears the interrupt flag on the current thread. If the catch block does not restore the flag by callingThread.currentThread().interrupt(), all upstream callers lose visibility into the fact that an interrupt was requested. This is a well-known correctness issue documented in Java Concurrency in Practice (section 7.1.2) and theInterruptedExceptionJavadoc.In a system like Pulsar — where graceful shutdown, topic unloading, and thread pool termination rely on cooperative interrupt signaling — swallowing the interrupt flag can cause:
Thread.interrupted()is silently skipped.Modifications
This PR adds
Thread.currentThread().interrupt()to 35 catch blocks across 31 files in the following modules:pulsar-broker(service)BrokerService,PersistentTopic,PersistentSubscription,NonPersistentTopicpulsar-broker(loadbalance)ServiceUnitStateChannelImpl,TransferShedder,BrokerRegistryImplpulsar-broker(namespace)OwnedBundle,OwnershipCachepulsar-broker(admin/web)PulsarWebResource,WebService,PackagesBase,NonPersistentTopics,LoadReportCommandpulsar-broker(compaction)StrategicTwoPhaseCompactorpulsar-broker(other)BookKeeperClientFactoryImpl,PulsarClusterMetadataTeardown,LocalBookkeeperEnsemblepulsar-broker-commonAuthorizationService,OneStageAuthenticationState,BookieRackAffinityMappingpulsar-commonFileUtils,FutureUtilmanaged-ledgerManagedLedgerImplpulsar-metadataPulsarRegistrationManager,PulsarLedgerUnderreplicationManager,PulsarLedgerAuditorManager,ZKSessionWatcher,MetadataStoreTableViewImplpulsar-proxyProxyStatspulsar-transactionMLTransactionLogImplFor catch blocks that handle only
InterruptedException, the fix is:For multi-catch blocks (e.g.
catch (InterruptedException | ExecutionException e)), the fix is:Verifying this change
This is a mechanical, behavior-preserving fix. Each change adds exactly one
Thread.currentThread().interrupt()call at the start of a catch block; no control flow or logic is altered.PulsarService.java,ExtensibleLoadManagerImpl.java,TopicTransactionBuffer.java).Documentation
doc-not-needed— No documentation changes needed for a bug fix that preserves existing behavior.🤖 Generated with Claude Code