Philippus commented on code in PR #621:
URL: https://github.com/apache/pekko-projection/pull/621#discussion_r3946569249
##########
kafka/src/main/scala/org/apache/pekko/projection/kafka/internal/KafkaSourceProviderImpl.scala:
##########
@@ -94,23 +94,30 @@ import org.apache.kafka.common.record.TimestampType
})
override def source(readOffsets: ReadOffsets):
Future[Source[ConsumerRecord[K, V], NotUsed]] = {
- // get the total number of partitions to configure the `breadth`
parameter, or we could just use a really large
- // number. i don't think using a large number would present a problem.
- val metadataClient = metadataClientFactory()
- val numPartitionsF = metadataClient.numPartitions(topics)
- numPartitionsF.failed.foreach(_ => metadataClient.stop())
- numPartitionsF.map { numPartitions =>
- _source(readOffsets, numPartitions, metadataClient)
- .mapMaterializedValue { m =>
- control = Some(m)
- m
+ // The metadata client is created when the source is materialized, and
stopped when the stream terminates.
+ // Creating it eagerly here would leak the client, and its Kafka consumer
actor, when the returned source is
+ // never materialized, such as when the projection is stopped while it is
starting up.
+ val source =
+ Source.lazyFutureSource[ConsumerRecord[K, V], NotUsed] { () =>
+ // get the total number of partitions to configure the `breadth`
parameter, or we could just use a really large
+ // number. i don't think using a large number would present a problem.
Review Comment:
```suggestion
// number. I don't think using a large number would present a
problem.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]