Skip to content

Commit 7e405cc

Browse files
authored
KAFKA-18758: NullPointerException in shutdown following InvalidConfigurationException (#18833)
* KAFKA-18758: NullPointerException in shutdown following InvalidConfigurationException Add checks for null in shutdown as BrokerLifecycleManager is not instantiaited if LogManager constructor throws an Exception
1 parent 675a088 commit 7e405cc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

core/src/main/scala/kafka/server/BrokerServer.scala

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -748,18 +748,22 @@ class BrokerServer(
748748
if (replicaManager != null)
749749
replicaManager.beginControlledShutdown()
750750

751-
lifecycleManager.beginControlledShutdown()
752-
try {
753-
val controlledShutdownTimeoutMs = deadline - time.milliseconds()
754-
lifecycleManager.controlledShutdownFuture.get(controlledShutdownTimeoutMs, TimeUnit.MILLISECONDS)
755-
} catch {
756-
case _: TimeoutException =>
757-
error("Timed out waiting for the controller to approve controlled shutdown")
758-
case e: Throwable =>
759-
error("Got unexpected exception waiting for controlled shutdown future", e)
751+
if (lifecycleManager != null) {
752+
lifecycleManager.beginControlledShutdown()
753+
try {
754+
val controlledShutdownTimeoutMs = deadline - time.milliseconds()
755+
lifecycleManager.controlledShutdownFuture.get(controlledShutdownTimeoutMs, TimeUnit.MILLISECONDS)
756+
} catch {
757+
case _: TimeoutException =>
758+
error("Timed out waiting for the controller to approve controlled shutdown")
759+
case e: Throwable =>
760+
error("Got unexpected exception waiting for controlled shutdown future", e)
761+
}
760762
}
761763
}
762-
lifecycleManager.beginShutdown()
764+
if (lifecycleManager != null)
765+
lifecycleManager.beginShutdown()
766+
763767
// Stop socket server to stop accepting any more connections and requests.
764768
// Socket server will be shutdown towards the end of the sequence.
765769
if (socketServer != null) {
@@ -811,8 +815,10 @@ class BrokerServer(
811815
if (clientToControllerChannelManager != null)
812816
CoreUtils.swallow(clientToControllerChannelManager.shutdown(), this)
813817

814-
if (logManager != null)
815-
CoreUtils.swallow(logManager.shutdown(lifecycleManager.brokerEpoch), this)
818+
if (logManager != null) {
819+
val brokerEpoch = if (lifecycleManager != null) lifecycleManager.brokerEpoch else -1
820+
CoreUtils.swallow(logManager.shutdown(brokerEpoch), this)
821+
}
816822

817823
// Close remote log manager to give a chance to any of its underlying clients
818824
// (especially in RemoteStorageManager and RemoteLogMetadataManager) to close gracefully.
@@ -832,7 +838,9 @@ class BrokerServer(
832838

833839
isShuttingDown.set(false)
834840

835-
CoreUtils.swallow(lifecycleManager.close(), this)
841+
if (lifecycleManager != null)
842+
CoreUtils.swallow(lifecycleManager.close(), this)
843+
836844
CoreUtils.swallow(config.dynamicConfig.clear(), this)
837845
Utils.closeQuietly(clientMetricsManager, "client metrics manager")
838846
sharedServer.stopForBroker()

0 commit comments

Comments
 (0)