kafkajs icon indicating copy to clipboard operation
kafkajs copied to clipboard

fetchTopicOffsets throws error when destructuring

Open talam opened this issue 5 years ago • 4 comments

I had a simple publisher/consumer setup running using a similar docker compose file setup to the one found in this repo and noticed that this code threw a destructing error.

        const high = await cluster.fetchTopicsOffset([
          {
            topic,
            fromBeginning: false,
            partitions: metadata.map(p => ({ partition: p.partitionId })),
          },
        ])

        const { partitions: highPartitions } = high.pop()

I don't have the exact error as i didn't copy it before my consumer's stdout log overwrote it in my terminal window due to limited length but it was something like

TypeError: Cannot destructure property `partitions` of 'undefined' or 'null'.

I suspect that cluster.fetchTopicsOffset is returning an empty array somehow causing the issue but I am unsure how that empty array would have been returned if my topic definitely has data in it. Even so, should there be a check added to that section to make sure we have something before trying to destructure it?

talam avatar Aug 09 '19 22:08 talam

Hey, any progress on that issue? We have it happens very often while using fetchTopicOffsets method

maxim-slavutsky avatar Apr 11 '20 01:04 maxim-slavutsky

No one has been working on this, to my knowledge. If anyone who is affected by this could contribute a repro case that would be of massive help.

Nevon avatar Apr 15 '20 06:04 Nevon

I also run into this problem. It did not happen on older versions (1 year ago) of KafkaJs.

samueltuckey avatar Oct 05 '22 05:10 samueltuckey

I ran into this when doing multiple calls to kafka.admin().fetchTopicOffsets(topicName) in parallel. It turns out that metadata in https://github.com/tulios/kafkajs/blob/ff3b1117f316d527ae170b550bc0f772614338e9/src/admin/index.js#L310 is then sometimes [] in that case. I did not investigate why this is happening.

everhardt avatar Jan 05 '24 11:01 everhardt