You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/01/08 17:01:48 UTC

[GitHub] tillrohrmann commented on a change in pull request #7020: [FLINK-10774] [Kafka] connection leak when partition discovery is disabled an…

tillrohrmann commented on a change in pull request #7020: [FLINK-10774] [Kafka] connection leak when partition discovery is disabled an…
URL: https://github.com/apache/flink/pull/7020#discussion_r246072609
 
 

 ##########
 File path: flink-connectors/flink-connector-kafka-base/src/main/java/org/apache/flink/streaming/connectors/kafka/FlinkKafkaConsumerBase.java
 ##########
 @@ -470,7 +470,20 @@ public void open(Configuration configuration) throws Exception {
 
 		subscribedPartitionsToStartOffsets = new HashMap<>();
 
-		List<KafkaTopicPartition> allPartitions = partitionDiscoverer.discoverPartitions();
+		List<KafkaTopicPartition> allPartitions;
+		try {
+			allPartitions = partitionDiscoverer.discoverPartitions();
+		} finally {
+			if (discoveryIntervalMillis == PARTITION_DISCOVERY_DISABLED) {
+				// when partition discovery is disabled,
+				// we should close partitionDiscoverer after the initial discovery.
+				// otherwise we may have connection leak,
+				// if open method throws an exception after partitionDiscoverer is constructed.
+				// In this case, run method won't be executed
+				// and partitionDiscoverer.close() won't be called.
+				partitionDiscoverer.close();
 
 Review comment:
   I think we also need to close the `partitionDiscoverer` in case of a failure if partition discovery is enabled.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services