nomisRev / kotlin-kafka

Kafka bindings for Kotlin `suspend`, and Kafka streaming operators for KotlinX Flow.
https://nomisRev.github.io/kotlin-kafka/
Apache License 2.0
103 stars 10 forks source link

[bug] Potential stack overflow on EventLoop.poll() #198

Open lsafer-meemer opened 2 months ago

lsafer-meemer commented 2 months ago

Here, when the channel successfully sends the records, the poll() function gets called and the current frame stuck in the stack. Therefore, the stack will keep growing infinitely if the channel kept successfully sending the records

https://github.com/nomisRev/kotlin-kafka/blob/9d7604f1a1d148b14578ae10979a02242a09ed64/src/main/kotlin/io/github/nomisRev/kafka/receiver/internals/EventLoop.kt#L124

https://github.com/nomisRev/kotlin-kafka/blob/9d7604f1a1d148b14578ae10979a02242a09ed64/src/main/kotlin/io/github/nomisRev/kafka/receiver/internals/EventLoop.kt#L173

nomisRev commented 2 months ago

Hey @lsafer-meemer,

Thank you or the bug report, and your interest in the project! Is there a reproducible snippet? We're missing quite some tests, complex scenarios are not always easy to write..

This should be testable by configuring a very low max.poll.size, and probably low poll time, to pull 20_000 records 1 by 1, successfully. A stack unsafe method should result in StackOverflow after 20_000 recursions, but we can also test 200_000 to be sure.

I'd love a contribution for this if you're interested 🙏

lsafer-meemer commented 2 months ago

Sorry, I actually don't know how the project works 😥

I just found it when I was randomly exploring and thought it was an issue 😬