{"record":{"id":"b18894e3cf689bc0","repo":"apache/kafka","slug":"failed-to-create-new-networkclient","errorCode":null,"errorMessage":"Failed to create new NetworkClient","messagePattern":"Failed to create new NetworkClient","errorType":"exception","errorClass":"KafkaException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/ClientUtils.java","lineNumber":279,"sourceCode":"                    requestTimeoutMs,\n                    config.getLong(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG),\n                    config.getLong(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG),\n                    time,\n                    true,\n                    apiVersions,\n                    throttleTimeSensor,\n                    logContext,\n                    hostResolver,\n                    clientTelemetrySender,\n                    config.getLong(CommonClientConfigs.METADATA_RECOVERY_REBOOTSTRAP_TRIGGER_MS_CONFIG),\n                    MetadataRecoveryStrategy.forName(config.getString(CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG)),\n                    bootstrapConfiguration,\n                    config.getBoolean(CommonClientConfigs.METADATA_CLUSTER_CHECK_ENABLE_CONFIG)\n            );\n        } catch (Throwable t) {\n            closeQuietly(selector, \"Selector\");\n            closeQuietly(channelBuilder, \"ChannelBuilder\");\n            throw new KafkaException(\"Failed to create new NetworkClient\", t);\n        }\n    }\n\n    public static <T> List<?> configuredInterceptors(AbstractConfig config,\n                                                    String interceptorClassesConfigName,\n                                                    Class<T> clazz) {\n        String clientId = config.getString(CommonClientConfigs.CLIENT_ID_CONFIG);\n        return config.getConfiguredInstances(\n                interceptorClassesConfigName,\n                clazz,\n                Collections.singletonMap(CommonClientConfigs.CLIENT_ID_CONFIG, clientId));\n    }\n\n    public static ClusterResourceListeners configureClusterResourceListeners(List<?>... candidateLists) {\n        ClusterResourceListeners clusterResourceListeners = new ClusterResourceListeners();\n\n        for (List<?> candidateList: candidateLists)\n            clusterResourceListeners.maybeAddAll(candidateList);","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java#L261-L297","documentation":"KafkaException thrown by ClientUtils.createNetworkClient wrapping any Throwable raised while constructing the NetworkClient (or the selector/channelBuilder prepared just before it). It cleans up by closing the selector and channelBuilder before rethrowing, so partial resources are not leaked. The cause identifies the real failure (config, IO, DNS, channel-builder, telemetry-sender, etc.).","triggerScenarios":"catch (Throwable t) at line 276 wraps anything thrown by BootstrapConfiguration.enabled(...) or the new NetworkClient(...) constructor (lines 246-275). Common causes: ConfigException from bad bootstrap.servers, IllegalArgument from MetadataRecoveryStrategy.forName, channel-builder/SASL misconfiguration, NPE from a null dependency passed in.","commonSituations":"Invalid metadata.recovery.strategy value (see error 19); bad bootstrap.servers; missing/invalid SASL or SSL config; null hostResolver or clientTelemetrySender; incompatible config combos caught inside NetworkClient.","solutions":["Read the wrapped cause (t.getCause()) — it names the actual config or construction problem.","Fix the underlying issue (bootstrap URL, SASL mechanism, metadata.recovery.strategy, etc.).","Enable DEBUG/TRACE logging for org.apache.kafka.clients to see which construction step failed.","If integrating NetworkClient directly, ensure all non-null args (hostResolver, telemetrySender, bootstrapConfiguration) are provided."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate the components that commonly cause NetworkClient construction failure\nObjects.requireNonNull(hostResolver, \"hostResolver\");\nObjects.requireNonNull(clientTelemetrySender, \"clientTelemetrySender\");\nMetadataRecoveryStrategy.forName(strategyName); // surfaces bad value early\nBootstrapConfiguration.enabled(bootstrapServers, dns, t, backoff);","typeGuard":null,"tryCatchPattern":"try { ClientUtils.createNetworkClient(...); } catch (KafkaException e) { Throwable c = e.getCause(); /* inspect c: ConfigException -> fix config; IllegalArgumentException -> bad enum/arg; etc. */ throw e; }","preventionTips":["Always inspect the wrapped cause rather than the generic 'Failed to create new NetworkClient'.","Validate bootstrap.servers, SASL, and metadata.recovery.strategy before construction.","Provide all non-null collaborators (hostResolver, telemetrySender)."],"tags":["kafka-client","network","config","initialization"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}